Skip to content

Commit

Permalink
test: improve e2e (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
licg9999 committed Jun 28, 2023
1 parent cfe17ce commit dbc38b4
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 107 deletions.
35 changes: 25 additions & 10 deletions e2e/basic-use-in-different-formats.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const OUTPUT_REG = /"a":"a\+".*"a":"a".*"a":"a\+".*"a":"a\+\+".*"a":"a".*"a":"a\

beforeAll(() => {
process.chdir(BASE_DIR);

throwErrIfNpmErr(
crossSpawn.sync('npm', ['uninstall', '--no-save', PKG_NAME]),
`Failed to uninstall '${PKG_NAME}'`
Expand All @@ -31,14 +32,26 @@ beforeAll(() => {
);
appendLogsToStatofuInNodeModules();
throwErrIfNpmErr(crossSpawn.sync('npx', ['webpack']), 'Webpack failure');
throwErrIfNpmErr(
crossSpawn.sync('npx', [
'webpack',
'--config',
'./obsolete-module-resolution/webpack.config.js',
]),
'Webpack failure (obsolete module resolution)'
);

['obsolete-module-resolution'].forEach((subdir) => {
try {
fs.rmSync(`${subdir}/dist`, { recursive: true });
} catch {}
throwErrIfNpmErr(
crossSpawn.sync('node', [`${subdir}/scripts/prepare.js`]),
`Failed to prepare dir '${subdir}'`
);
throwErrIfNpmErr(
crossSpawn.sync('npx', [
'webpack',
'--config',
`./${subdir}/webpack.config.js`,
'--config',
`./${subdir}/webpack.merge.config.js`,
]),
`Webpack failure (in subdir '${subdir}')`
);
});
});

afterAll(() => {
Expand Down Expand Up @@ -75,8 +88,10 @@ describe('on node', () => {
['import-cjs-by-default', 'require-cjs-by-default'].forEach((fullFormat) => {
test(`in format '${fullFormat}', runs well with the correct files imported`, () => {
const { importedFormat, subdirEndingWithSlash, mainFileFormat } = parseFullFormat(fullFormat);
const mainPrefix = `${subdirEndingWithSlash}src/index.node-${mainFileFormat}`;
const mainFile = [`${mainPrefix}.js`, `${mainPrefix}.mjs`].find((p) => fs.existsSync(p));
const mainFilePrefix = `${subdirEndingWithSlash}src/index.node-${mainFileFormat}`;
const mainFile = [`${mainFilePrefix}.js`, `${mainFilePrefix}.mjs`].find((p) =>
fs.existsSync(p)
);
if (!mainFile) {
throw new Error('Main file not found');
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
src/appLogics.js
global.d.ts
jest.config.js
webpack.config.js

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const fs = require('node:fs');

const toCopy = {
'../../src/appLogics.js': '../src/appLogics.js',
'../../global.d.ts': '../global.d.ts',
'../../jest.config.js': '../jest.config.js',
'../../webpack.config.js': '../webpack.config.js',
};

for (const [k, v] of Object.entries(toCopy)) {
fs.copyFileSync(`${__dirname}/${k}`, `${__dirname}/${v}`);
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw Error('File not implemented');
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
throw Error('File not implemented');
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"checkJs": false,
"moduleResolution": "node",
"rootDir": "."
},
"include": [".", "../global.d.ts"]
"include": ["."]
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/**
* @type {import("webpack").Configuration}
*/
const webpackConf = {
context: __dirname,
};

module.exports = webpackConf;

0 comments on commit dbc38b4

Please sign in to comment.