Skip to content

Commit 58fea8f

Browse files
authored
chore(e2e): chdir back to the previous dir at the end of a test. (#3287)
1 parent dd7b74d commit 58fea8f

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

tests/e2e/tests/commands/help.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@ import {silentNg} from '../../utils/process';
22

33

44
export default function() {
5-
const projectDir = process.cwd();
65
return Promise.resolve()
76
.then(() => silentNg('help'))
87
.then(() => process.chdir('/'))
9-
.then(() => silentNg('help'))
10-
.then(() => process.chdir(projectDir));
8+
.then(() => silentNg('help'));
119
}

tests/e2e/tests/packages/webpack/test.ts

-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import {expectFileSizeToBeUnder} from '../../../utils/fs';
66

77

88
export default function(argv: any, skipCleaning: () => void) {
9-
const currentDir = process.cwd();
10-
119
if (process.platform.startsWith('win')) {
1210
// Disable the test on Windows.
1311
return Promise.resolve();
@@ -24,6 +22,5 @@ export default function(argv: any, skipCleaning: () => void) {
2422
.then(() => exec('node_modules/.bin/webpack', '-p'))
2523
.then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000))
2624
.then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000))
27-
.then(() => process.chdir(currentDir))
2825
.then(() => skipCleaning());
2926
}

tests/e2e_runner.js

+9
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,19 @@ testsToRun.reduce((previous, relativeName) => {
9292
};
9393

9494
let clean = true;
95+
let previousDir = null;
9596
return Promise.resolve()
9697
.then(() => printHeader(currentFileName))
98+
.then(() => previousDir = process.cwd())
9799
.then(() => fn(argv, () => clean = false))
98100
.then(() => console.log(' ----'))
101+
.then(() => {
102+
// If we're not in a setup, change the directory back to where it was before the test.
103+
// This allows tests to chdir without worrying about keeping the original directory.
104+
if (allSetups.indexOf(relativeName) == -1 && previousDir) {
105+
process.chdir(previousDir);
106+
}
107+
})
99108
.then(() => {
100109
// Only clean after a real test, not a setup step. Also skip cleaning if the test
101110
// requested an exception.

0 commit comments

Comments
 (0)