Skip to content

Commit f810c35

Browse files
committed
chore(e2e): chdir back to the previous dir at the end of a test.
1 parent bf9c8f1 commit f810c35

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,8 +92,10 @@ 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(' ----'))
99101
.then(() => {
@@ -103,6 +105,13 @@ testsToRun.reduce((previous, relativeName) => {
103105
return gitClean();
104106
}
105107
})
108+
.then(() => {
109+
// If we're not in a setup, change the directory back to where it was before the test.
110+
// This allows tests to chdir without worrying about keeping the original directory.
111+
if (allSetups.indexOf(relativeName) == -1 && previousDir) {
112+
process.chdir(previousDir);
113+
}
114+
})
106115
.then(() => printFooter(currentFileName, start),
107116
(err) => {
108117
printFooter(currentFileName, start);

0 commit comments

Comments
 (0)