Skip to content

Commit d3f9dfd

Browse files
committed
test: e2e exec() now returns an object {stdout,stderr}
Before it was only a string with stdout.
1 parent 5d3c5dc commit d3f9dfd

File tree

9 files changed

+50
-31
lines changed

9 files changed

+50
-31
lines changed

tests/e2e/tests/commands/config/get.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,19 @@ export default function() {
77
.then(() => process.chdir('/'))
88
.then(() => expectToFail(() => ng('get', 'defaults.component.inlineStyle')))
99
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
10-
.then(output => {
11-
if (!output.match(/false\n?/)) {
12-
throw new Error(`Expected "false", received "${JSON.stringify(output)}".`);
10+
.then(({ stdout }) => {
11+
if (!stdout.match(/false\n?/)) {
12+
throw new Error(`Expected "false", received "${JSON.stringify(stdout)}".`);
1313
}
1414
})
1515
.then(() => expectToFail(() => {
1616
return ng('set', '--global', 'defaults.component.inlineStyle', 'INVALID_BOOLEAN');
1717
}))
1818
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'true'))
1919
.then(() => ng('get', '--global', 'defaults.component.inlineStyle'))
20-
.then(output => {
21-
if (!output.match(/true\n?/)) {
22-
throw new Error(`Expected "true", received "${JSON.stringify(output)}".`);
20+
.then(({ stdout }) => {
21+
if (!stdout.match(/true\n?/)) {
22+
throw new Error(`Expected "true", received "${JSON.stringify(stdout)}".`);
2323
}
2424
})
2525
.then(() => ng('set', '--global', 'defaults.component.inlineStyle', 'false'));

tests/e2e/tests/commands/new/check-yarn.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ export default function() {
88
.then(() => process.chdir(getGlobalVariable('tmp-root')))
99
.then(() => ng('set', '--global', 'packageManager=default'))
1010
.then(() => ng('new', 'foo'))
11-
.then((stdout) => {
11+
.then(({ stdout }) => {
1212
// Assuming yarn is installed and checking for message with yarn.
13-
if (!stdout.toString().match(yarnRegEx)) {
13+
if (!stdout.match(yarnRegEx)) {
1414
throw new Error('Should display message to use yarn packageManager');
1515
}
1616
});

tests/e2e/tests/lint/lint-no-config-section.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ export default function () {
55
return Promise.resolve()
66
.then(() => ng('set', 'lint', '[]'))
77
.then(() => ng('lint'))
8-
.then((output) => {
9-
if (!output.match(/No lint config\(s\) found\./)) {
8+
.then(({ stdout }) => {
9+
if (!stdout.match(/No lint config\(s\) found\./)) {
1010
throw new Error(oneLine`
1111
Expected to match "No lint configs found."
12-
in ${output}.
12+
in ${stdout}.
1313
`);
1414
}
1515

16-
return output;
16+
return stdout;
1717
})
1818
.then((output) => {
1919
if (!output.match(/If this is not intended, run "ng update"\./)) {

tests/e2e/tests/lint/lint-with-exclude.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ export default function () {
99
.then(() => ng('set', 'lint.0.exclude', '"**/foo.ts"'))
1010
.then(() => writeFile(fileName, 'const foo = "";\n'))
1111
.then(() => ng('lint'))
12-
.then((output) => {
13-
if (!output.match(/All files pass linting\./)) {
12+
.then(({ stdout }) => {
13+
if (!stdout.match(/All files pass linting\./)) {
1414
throw new Error(oneLine`
1515
Expected to match "All files pass linting."
16-
in ${output}.
16+
in ${stdout}.
1717
`);
1818
}
1919
});

tests/e2e/tests/lint/lint-with-force.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ export default function () {
88
return Promise.resolve()
99
.then(() => writeFile(fileName, 'const foo = "";\n'))
1010
.then(() => ng('lint', '--force'))
11-
.then((output) => {
12-
if (!output.match(/" should be '/)) {
13-
throw new Error(`Expected to match "" should be '" in ${output}.`);
11+
.then(({ stdout }) => {
12+
if (!stdout.match(/" should be '/)) {
13+
throw new Error(`Expected to match "" should be '" in ${stdout}.`);
1414
}
1515

16-
return output;
16+
return stdout;
1717
})
1818
.then((output) => {
1919
if (!output.match(/Lint errors found in the listed files\./)) {

tests/e2e/tests/lint/lint-with-format.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ export default function () {
88
return Promise.resolve()
99
.then(() => writeFile(fileName, 'const foo = "";\n'))
1010
.then(() => ng('lint', '--format=stylish', '--force'))
11-
.then((output) => {
12-
if (!output.match(/1:13 quotemark " should be '/)) {
11+
.then(({ stdout }) => {
12+
if (!stdout.match(/1:13 quotemark " should be '/)) {
1313
throw new Error(oneLine`
1414
Expected to match "1:13 quotemark " should be '"
15-
in ${output}.
15+
in ${stdout}.
1616
`);
1717
}
1818
});

tests/e2e/tests/lint/lint.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ import { oneLine } from 'common-tags';
33

44
export default function () {
55
return ng('lint')
6-
.then((output) => {
7-
if (!output.match(/All files pass linting\./)) {
6+
.then(({ stdout }) => {
7+
if (!stdout.match(/All files pass linting\./)) {
88
throw new Error(oneLine`
99
Expected to match "All files pass linting."
10-
in ${output}.
10+
in ${stdout}.
1111
`);
1212
}
1313
});

tests/e2e/utils/git.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export function gitClean() {
88
.then(() => {
99
// Checkout missing files
1010
return silentGit('status', '--porcelain')
11-
.then(output => output
11+
.then(({ stdout }) => stdout
1212
.split(/[\n\r]+/g)
1313
.filter(line => line.match(/^ D/))
1414
.map(line => line.replace(/^\s*\S+\s+/, '')))
@@ -19,8 +19,8 @@ export function gitClean() {
1919

2020
export function expectGitToBeClean() {
2121
return git('status', '--porcelain')
22-
.then(output => {
23-
if (output != '') {
22+
.then(({ stdout }) => {
23+
if (stdout != '') {
2424
throw new Error('Git repo is not clean...');
2525
}
2626
});
@@ -29,8 +29,8 @@ export function expectGitToBeClean() {
2929
export function gitCommit(message: string) {
3030
return git('add', '-A')
3131
.then(() => git('status', '--porcelain'))
32-
.then(output => {
33-
if (output != '') {
32+
.then(({ stdout }) => {
33+
if (stdout != '') {
3434
return git('commit', '-am', message);
3535
}
3636
});

tests/e2e/utils/process.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import * as child_process from 'child_process';
22
import {blue, yellow} from 'chalk';
3+
import {getGlobalVariable} from './env';
4+
import {rimraf, writeFile} from './fs';
35
const treeKill = require('tree-kill');
46

57

@@ -75,7 +77,7 @@ function _exec(options: ExecOptions, cmd: string, args: string[]): Promise<Proce
7577
_processes = _processes.filter(p => p !== childProcess);
7678

7779
if (!error) {
78-
resolve(stdout);
80+
resolve({ stdout });
7981
} else {
8082
err.message += `${error}...\n\nSTDOUT:\n${stdout}\n`;
8183
reject(err);
@@ -134,9 +136,26 @@ export function silentExecAndWaitForOutputToMatch(cmd: string, args: string[], m
134136
return _exec({ silent: true, waitForMatch: match }, cmd, args);
135137
}
136138

139+
140+
let npmInstalledEject = false;
137141
export function ng(...args: string[]) {
138142
// Auto-add --no-progress to commands that build the app, otherwise we get thousands of lines.
139143
if (['build', 'serve', 'test', 'e2e', 'xi18n'].indexOf(args[0]) != -1) {
144+
// If we have the --eject, use webpack for the test.
145+
const argv = getGlobalVariable('argv');
146+
if (args[0] == 'build' && argv.eject) {
147+
return silentNg('eject', ...args.slice(1), '--force')
148+
.then(() => {
149+
if (!npmInstalledEject) {
150+
npmInstalledEject = true;
151+
// We need to run npm install on the first eject.
152+
return silentNpm('install');
153+
}
154+
})
155+
.then(() => rimraf('dist'))
156+
.then(() => _exec({silent: true}, 'node_modules/.bin/webpack', []));
157+
}
158+
140159
return silentNg(...args, '--no-progress');
141160
} else {
142161
return _exec({}, 'ng', args);

0 commit comments

Comments
 (0)