Skip to content

Commit

Permalink
test: Add the readModuleOptions test case.
Browse files Browse the repository at this point in the history
  • Loading branch information
jiuhuan committed Apr 3, 2023
1 parent 85f995a commit b7857b8
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin/config/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
],
"types": "typings/index.d.ts",
"scripts": {
"test": "cross-env NODE_ENV=test NODE_OPTIONS='--no-deprecation' mocha",
"clean": "tsc -b --clean",
"tsc": "npm run clean && tsc -p ./tsconfig.json",
"tsc:pub": "npm run clean && tsc -p ./tsconfig.pub.json",
Expand Down
40 changes: 40 additions & 0 deletions plugin/config/test/ReadModule.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import mm from 'egg-mock';
import assert from 'assert';
import path from 'path';

describe('test/ReadModule.test.ts', () => {
let app;
const fixturesPath = path.join(__dirname, './fixtures/apps/app-with-modules');

after(async () => {
await app.close();
});

afterEach(() => {
mm.restore();
});

before(async () => {
mm(process.env, 'EGG_TYPESCRIPT', true);
mm(process, 'cwd', () => {
return path.join(__dirname, '..');
});
app = mm.app({
baseDir: fixturesPath,
framework: require.resolve('egg'),
});
await app.ready();
});

it('should work', async () => {
assert.deepStrictEqual(app.moduleConfigs, {
moduleA: {
config: {},
name: 'moduleA',
reference: {
path: path.join(fixturesPath, 'app/module-a'),
},
},
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"name": "module-a",
"eggModule": {
"name": "moduleA"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
export default () => {
return {
tegg: {
readModuleOptions: {
extraFilePattern: [ '!**/dist' ],
},
},
};
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"name": "foo"
}

0 comments on commit b7857b8

Please sign in to comment.