Skip to content

Commit

Permalink
chore: 补充单测
Browse files Browse the repository at this point in the history
  • Loading branch information
Jinbao1001 committed Aug 9, 2024
1 parent f38ead2 commit 3806cdf
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import type { IConfig as IBundlerWebpackConfig } from '@umijs/bundler-webpack/di
import type { IAdd, IModify, IServicePluginAPI, PluginAPI } from '@umijs/core';
import type { ITransformerItem } from './builder/bundless/loaders/javascript';
import type {
createConfigProviders,
IBundleConfig,
IBundlessConfig,
createConfigProviders,
} from './builder/config';
import type { IDoctorReport } from './doctor';
import type { IDoctorSourceParseResult } from './doctor/parser';
Expand Down Expand Up @@ -159,6 +159,11 @@ export interface IFatherBundlessConfig extends IFatherBaseConfig {
* ignore specific directories & files via ignore syntax
*/
ignores?: string[];

/**
* compiler parallel
*/
parallel?: boolean;
}

export interface IFatherBundleConfig extends IFatherBaseConfig {
Expand Down
68 changes: 68 additions & 0 deletions tests/parallel.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import path from 'path';
import * as cli from '../dist/cli/cli';
import { distToMap, getDirCases } from './utils';

global.CASES_DIR = path.join(__dirname, 'fixtures/build');

const setupRcFileMocks = (cases, casesDir) => {
cases.forEach((name) => {
const rcFilePath = path.join(casesDir, name, '.fatherrc.ts');
jest.doMock(rcFilePath, () => {
const originalModule = jest.requireActual(rcFilePath);
console.log(originalModule.default, 'originalModule');
originalModule.default.esm &&
(originalModule.default.esm = {
...originalModule.default.esm,
parallel: true,
});
originalModule.default.cjs &&
(originalModule.default.cjs = {
...originalModule.default.cjs,
parallel: true,
});
return {
__esModule: true,
default: originalModule.default,
};
});
});
};

const uninstallRcFileMocks = (cases, casesDir) => {
cases.forEach((name) => {
const rcFilePath = path.join(casesDir, name, '.fatherrc.ts');
jest.unmock(rcFilePath);
});
};

beforeAll(() => {
process.env.FATHER_CACHE = 'none';
setupRcFileMocks(cases, global.CASES_DIR);
});

afterAll(() => {
uninstallRcFileMocks(cases, global.CASES_DIR);
delete process.env.APP_ROOT;
delete process.env.FATHER_CACHE;
});

// generate cases
const cases = getDirCases(global.CASES_DIR).filter((item) =>
item.includes('bundless'),
);

for (let name of cases) {
test(`parllel build: ${name}`, async () => {
// execute build
process.env.APP_ROOT = path.join(global.CASES_DIR, name);
await cli.run({
args: { _: ['build'], $0: 'node' },
});

// prepare file map
const fileMap = distToMap(path.join(global.CASES_DIR, name, 'dist'));

// check result
require(`${global.CASES_DIR}/${name}/expect`).default(fileMap);
});
}

0 comments on commit 3806cdf

Please sign in to comment.