-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved. | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
import * as path from 'path'; | ||
import {tmpdir} from 'os'; | ||
import {skipSuiteOnWindows} from '@jest/test-utils'; | ||
import {cleanup, writeFiles} from '../Utils'; | ||
import runJest from '../runJest'; | ||
|
||
const DIR = path.resolve(tmpdir(), 'existent-roots'); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterAll(() => cleanup(DIR)); | ||
|
||
skipSuiteOnWindows(); | ||
|
||
function writeConfig(rootDir: string, roots?: Array<string>) { | ||
writeFiles(DIR, { | ||
'jest.config.js': ` | ||
module.exports = ${JSON.stringify({rootDir, roots}, null, 2)}; | ||
`, | ||
'package.json': '{}', | ||
}); | ||
} | ||
|
||
test('error when rootDir does not exist', () => { | ||
const fakeRootDir = path.join(DIR, 'foobar'); | ||
writeConfig(fakeRootDir); | ||
|
||
const {exitCode, stderr} = runJest(DIR); | ||
|
||
expect(exitCode).toBe(1); | ||
expect(stderr).toContain( | ||
`Directory ${fakeRootDir} in the rootDir option was not found.`, | ||
); | ||
}); | ||
|
||
test('error when rootDir is a file', () => { | ||
const fakeRootDir = path.join(DIR, 'jest.config.js'); | ||
writeConfig(fakeRootDir); | ||
|
||
const {exitCode, stderr} = runJest(DIR); | ||
|
||
expect(exitCode).toBe(1); | ||
expect(stderr).toContain( | ||
`${fakeRootDir} in the rootDir option is not a directory.`, | ||
); | ||
}); | ||
|
||
test('error when roots directory does not exist', () => { | ||
const fakeRootDir = path.join(DIR, 'foobar'); | ||
writeConfig(DIR, ['<rootDir>', fakeRootDir]); | ||
|
||
const {exitCode, stderr} = runJest(DIR); | ||
|
||
expect(exitCode).toBe(1); | ||
expect(stderr).toContain( | ||
`Directory ${fakeRootDir} in the roots[1] option was not found.`, | ||
); | ||
}); | ||
|
||
test('error when roots is a file', () => { | ||
const fakeRootDir = path.join(DIR, 'jest.config.js'); | ||
writeConfig(DIR, ['<rootDir>', fakeRootDir]); | ||
|
||
const {exitCode, stderr} = runJest(DIR); | ||
|
||
expect(exitCode).toBe(1); | ||
expect(stderr).toContain( | ||
`${fakeRootDir} in the roots[1] option is not a directory.`, | ||
); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters