-
-
Notifications
You must be signed in to change notification settings - Fork 6.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: verify rootDir
and all roots
are directories
#9569
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
7cc61eb
fix: verify `rootDir` and all `roots` are directories
SimenB bb56174
link to PR
SimenB e3f78a0
fix tests
SimenB 6d9e3d4
simplify new test
SimenB 62bfb8a
realpath tmpdir
SimenB 33c2b72
Revert "realpath tmpdir"
SimenB eb69703
skip on windows
SimenB File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printing a warning instead of these 3
throw
s is trivial if we don't want a breaking change. However, I think non-existent directories provided to these options are so blatantly a configuration error that I think it's fine to throw