Skip to content

Commit 65c76aa

Browse files
committed
Migrate test/* test files to Vitest
1 parent 6d07e3a commit 65c76aa

File tree

8 files changed

+3338
-3194
lines changed

8 files changed

+3338
-3194
lines changed

test/WebpackConfig.js renamed to test/WebpackConfig.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const expect = require('chai').expect;
12+
import { describe, it, expect, beforeEach, afterEach } from 'vitest';
1313
const WebpackConfig = require('../lib/WebpackConfig');
1414
const RuntimeConfig = require('../lib/config/RuntimeConfig');
1515
const path = require('path');

test/bin/encore.test.js

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -308,26 +308,18 @@ module.exports = Encore.getWebpackConfig();
308308
);
309309

310310
const binPath = path.resolve(projectDir, 'bin', 'encore.js');
311-
try {
312-
await execAsync(`node ${binPath} dev-server --context=${testDir}`, {
313-
cwd: testDir,
314-
env: Object.assign({}, process.env, { NO_COLOR: 'true' })
315-
});
316-
317-
throw new Error('Expected command to fail.');
318-
} catch (err) {
319-
if (!'stdout' in err || !'stderr' in err) {
320-
throw new Error(`Error executing encore: ${err}`);
321-
}
311+
const { stdout, stderr } = await execAsync(`node ${binPath} dev-server --context=${testDir}`, {
312+
cwd: testDir,
313+
env: Object.assign({}, process.env, { NO_COLOR: 'true' })
314+
});
322315

323-
expect(err.stdout).to.contain('Install webpack-dev-server to use the webpack Development Server');
324-
expect(err.stdout).to.contain('npm install webpack-dev-server --save-dev');
325-
expect(err.stderr).to.equal('');
316+
expect(stdout).to.contain('Install webpack-dev-server to use the webpack Development Server');
317+
expect(stdout).to.contain('npm install webpack-dev-server --save-dev');
318+
expect(stderr).to.equal('');
326319

327-
expect(err.stdout).not.to.contain('Running webpack-dev-server ...');
328-
expect(err.stdout).not.to.contain('Compiled successfully in');
329-
expect(err.stdout).not.to.contain('webpack compiled successfully');
330-
}
320+
expect(stdout).not.to.contain('Running webpack-dev-server ...');
321+
expect(stdout).not.to.contain('Compiled successfully in');
322+
expect(stdout).not.to.contain('webpack compiled successfully');
331323
});
332324
});
333325
});

test/config-generator.js renamed to test/config-generator.test.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
'use strict';
1111

12-
const expect = require('chai').expect;
12+
import { describe, it, expect, beforeEach, beforeAll, afterAll } from 'vitest';
1313
const WebpackConfig = require('../lib/WebpackConfig');
1414
const RuntimeConfig = require('../lib/config/RuntimeConfig');
1515
const configGenerator = require('../lib/config-generator');
@@ -965,23 +965,25 @@ describe('The config-generator function', () => {
965965
});
966966

967967
describe('Test shouldSplitEntryChunks', () => {
968-
const config = createConfig();
969-
config.outputPath = '/tmp/public/build';
970-
config.setPublicPath('/build/');
971-
config.splitEntryChunks();
972-
973-
const actualConfig = configGenerator(config);
974-
expect(actualConfig.optimization.splitChunks.chunks).to.equal('all');
975-
expect(actualConfig.optimization.splitChunks.name).to.be.undefined;
968+
it('with defaults', () => {
969+
const config = createConfig();
970+
config.outputPath = '/tmp/public/build';
971+
config.setPublicPath('/build/');
972+
config.splitEntryChunks();
973+
974+
const actualConfig = configGenerator(config);
975+
expect(actualConfig.optimization.splitChunks.chunks).to.equal('all');
976+
expect(actualConfig.optimization.splitChunks.name).to.be.undefined;
977+
})
976978
});
977979

978980
describe('Test shouldUseSingleRuntimeChunk', () => {
979-
before(() => {
981+
beforeAll(() => {
980982
logger.reset();
981983
logger.quiet();
982984
});
983985

984-
after(() => {
986+
afterAll(() => {
985987
logger.quiet(false);
986988
});
987989

0 commit comments

Comments
 (0)