Skip to content

Commit

Permalink
fix(plugin-vite): util/package test
Browse files Browse the repository at this point in the history
  • Loading branch information
caoxiemeihao committed Jan 1, 2024
1 parent 478d5e6 commit e2f9bec
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/plugin/vite/test/fixture/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# lockfile
package-lock.json
pnpm-lock.yaml
yarn.lock
7 changes: 7 additions & 0 deletions packages/plugin/vite/test/fixture/package/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "@electron-forge/plugin-vite-test-util-package",
"version": "0.1.0",
"dependencies": {
"electron-squirrel-startup": "^1.0.0"
}
}
78 changes: 78 additions & 0 deletions packages/plugin/vite/test/util/package_spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { exec } from 'node:child_process';
import fs from 'node:fs';
import path from 'node:path';
import { promisify } from 'node:util';

import { expect } from 'chai';

import { getFlatDependencies, lookupNodeModulesPaths, readPackageJson, resolveDependencies } from '../../src/util/package';

const execPromise = promisify(exec);
const packageRoot = path.join(__dirname, '../fixture/package');
const packageJson = JSON.parse(fs.readFileSync(path.join(packageRoot, 'package.json'), 'utf8'));
const depsTree = [
{
name: 'electron-squirrel-startup',
path: {
src: path.join(packageRoot, 'node_modules', 'electron-squirrel-startup'),
dest: path.join('node_modules', 'electron-squirrel-startup'),
},
dependencies: [
{
name: 'debug',
path: {
src: path.join(packageRoot, 'node_modules', 'debug'),
dest: path.join('node_modules', 'debug'),
},
dependencies: [
{
name: 'ms',
path: {
src: path.join(packageRoot, 'node_modules', 'ms'),
dest: path.join('node_modules', 'ms'),
},
dependencies: [],
},
],
},
],
},
];
const depsFlat = [
{
src: path.join(packageRoot, 'node_modules', 'electron-squirrel-startup'),
dest: path.join('node_modules', 'electron-squirrel-startup'),
},
{
src: path.join(packageRoot, 'node_modules', 'debug'),
dest: path.join('node_modules', 'debug'),
},
{
src: path.join(packageRoot, 'node_modules', 'ms'),
dest: path.join('node_modules', 'ms'),
},
];

describe('package', () => {
before(async () => {
await execPromise('npm install', { cwd: packageRoot });
});

it('package.json is loaded correct', async () => {
const packageJson2 = await readPackageJson(packageRoot);
expect(typeof packageJson2).equal('object');
expect(packageJson2).deep.equal(packageJson);
});

it('dependencies of package.json is resolved correct', async () => {
const depsT = await resolveDependencies(packageRoot);
const depsF = await getFlatDependencies(packageRoot);
expect(depsTree).deep.equal(depsT);
expect(depsFlat).deep.equal(depsF);
});

it('node_modules paths is lookup correct', async () => {
const paths = await lookupNodeModulesPaths(packageRoot);
expect(paths.length).gt(0);
});
});

0 comments on commit e2f9bec

Please sign in to comment.