diff --git a/tests/e2e/tests/commands/help.ts b/tests/e2e/tests/commands/help.ts index ad268b78ab64..b2800c120cc3 100644 --- a/tests/e2e/tests/commands/help.ts +++ b/tests/e2e/tests/commands/help.ts @@ -2,10 +2,8 @@ import {silentNg} from '../../utils/process'; export default function() { - const projectDir = process.cwd(); return Promise.resolve() .then(() => silentNg('help')) .then(() => process.chdir('/')) - .then(() => silentNg('help')) - .then(() => process.chdir(projectDir)); + .then(() => silentNg('help')); } diff --git a/tests/e2e/tests/packages/webpack/test.ts b/tests/e2e/tests/packages/webpack/test.ts index 26c848e97636..2aef881606f5 100644 --- a/tests/e2e/tests/packages/webpack/test.ts +++ b/tests/e2e/tests/packages/webpack/test.ts @@ -6,8 +6,6 @@ import {expectFileSizeToBeUnder} from '../../../utils/fs'; export default function(argv: any, skipCleaning: () => void) { - const currentDir = process.cwd(); - if (process.platform.startsWith('win')) { // Disable the test on Windows. return Promise.resolve(); @@ -24,6 +22,5 @@ export default function(argv: any, skipCleaning: () => void) { .then(() => exec('node_modules/.bin/webpack', '-p')) .then(() => expectFileSizeToBeUnder('dist/app.main.js', 400000)) .then(() => expectFileSizeToBeUnder('dist/0.app.main.js', 40000)) - .then(() => process.chdir(currentDir)) .then(() => skipCleaning()); } diff --git a/tests/e2e_runner.js b/tests/e2e_runner.js index b66eee1495b8..dc264f3eb4d3 100644 --- a/tests/e2e_runner.js +++ b/tests/e2e_runner.js @@ -92,10 +92,19 @@ testsToRun.reduce((previous, relativeName) => { }; let clean = true; + let previousDir = null; return Promise.resolve() .then(() => printHeader(currentFileName)) + .then(() => previousDir = process.cwd()) .then(() => fn(argv, () => clean = false)) .then(() => console.log(' ----')) + .then(() => { + // If we're not in a setup, change the directory back to where it was before the test. + // This allows tests to chdir without worrying about keeping the original directory. + if (allSetups.indexOf(relativeName) == -1 && previousDir) { + process.chdir(previousDir); + } + }) .then(() => { // Only clean after a real test, not a setup step. Also skip cleaning if the test // requested an exception.