Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Commit c11b1c9

Browse files
authored
Test create-project buildable in development mode (#1082)
* Test create-project buildable in development mode * Fix failing create-project tests * Add comment about necessity of create-project test --mode development
1 parent 1b4f92b commit c11b1c9

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

packages/create-project/test/cli_test.js

+18-7
Original file line numberDiff line numberDiff line change
@@ -51,25 +51,25 @@ const spawnP = (cmd, args, options) => new Promise((resolve, reject) => {
5151
child.stderr.on('data', data => { output += data.toString(); });
5252
child.on('close', code => (code === 0 ? resolve(code) : reject(output)));
5353
});
54-
const buildable = async (t, dir) => {
54+
const buildable = async (t, dir, args = []) => {
5555
try {
56-
await spawnP('yarn', ['build'], { cwd: dir, stdio: 'pipe' });
56+
await spawnP('yarn', ['build', ...args], { cwd: dir, stdio: 'pipe' });
5757
t.pass();
5858
} catch (output) {
5959
t.fail(`Failed to build project:\n\n${output}`);
6060
}
6161
};
62-
const testable = async (t, dir) => {
62+
const testable = async (t, dir, args = []) => {
6363
try {
64-
await spawnP('yarn', ['test'], { cwd: dir, stdio: 'pipe' });
64+
await spawnP('yarn', ['test', ...args], { cwd: dir, stdio: 'pipe' });
6565
t.pass();
6666
} catch (output) {
6767
t.fail(`Failed to test project:\n\n${output}`);
6868
}
6969
};
70-
const lintable = async (t, dir) => {
70+
const lintable = async (t, dir, args = []) => {
7171
try {
72-
await spawnP('yarn', ['lint'], { cwd: dir, stdio: 'pipe' });
72+
await spawnP('yarn', ['lint', ...args], { cwd: dir, stdio: 'pipe' });
7373
t.pass();
7474
} catch (output) {
7575
t.fail(`Failed to lint project:\n\n${output}`);
@@ -97,16 +97,27 @@ Object.keys(tests).forEach(projectName => {
9797
project: projectName,
9898
testRunner: tester || false
9999
});
100+
const pkgPath = join(dir, 'package.json');
100101

101102
t.truthy(dir);
102-
assert.file(join(dir, 'package.json'));
103+
assert.file(pkgPath);
103104
assert.file(join(dir, '.neutrinorc.js'));
104105
assert.file(join(dir, 'webpack.config.js'));
105106
assert.file(join(dir, '.eslintrc.js'));
106107

107108
await lintable(t, dir);
108109
await buildable(t, dir);
109110

111+
const pkg = require(pkgPath); // eslint-disable-line import/no-dynamic-require
112+
113+
// Building in development mode to emulating running webpack-dev-server
114+
// or webpack --watch without actually spawning the process and waiting.
115+
// TODO: Find a way in the future to actually test that the spawned watchers
116+
// produce the expected result.
117+
if ('start' in pkg.scripts) {
118+
await buildable(t, dir, ['--', '--mode', 'development']);
119+
}
120+
110121
if (tester) {
111122
if (tester === packages.JEST) {
112123
assert.file(join(dir, 'jest.config.js'));

0 commit comments

Comments
 (0)