-
-
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
Add path case-insensitivity if onlyChanged option is active, fixes #4644 #4730
Changes from 5 commits
78dadae
c47755f
af59143
b1c3f48
f3f4466
ed855fc
f6350d1
4c82bb5
aa941c6
a0157e7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,13 +14,10 @@ import os from 'os'; | |
import path from 'path'; | ||
const {cleanup, run, writeFiles} = require('../utils'); | ||
|
||
const skipOnWindows = require('../../scripts/skip_on_windows'); | ||
const DIR = path.resolve(os.tmpdir(), 'jest_only_changed'); | ||
const GIT = 'git -c user.name=jest_test -c [email protected]'; | ||
const HG = 'hg --config ui.username=jest_test'; | ||
|
||
skipOnWindows.suite(); | ||
|
||
beforeEach(() => cleanup(DIR)); | ||
afterEach(() => cleanup(DIR)); | ||
|
||
|
@@ -45,7 +42,7 @@ test('run only changed files', () => { | |
expect(stdout).toMatch('No tests found related to files'); | ||
|
||
({stderr} = runJest(DIR, ['-o', '--lastCommit'])); | ||
expect(stderr).toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
|
||
writeFiles(DIR, { | ||
'__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, | ||
|
@@ -56,9 +53,9 @@ test('run only changed files', () => { | |
|
||
({stderr} = runJest(DIR, ['-o'])); | ||
|
||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
|
||
run(`${GIT} add .`, DIR); | ||
run(`${GIT} commit -m "second"`, DIR); | ||
|
@@ -71,9 +68,9 @@ test('run only changed files', () => { | |
}); | ||
|
||
({stderr} = runJest(DIR, ['-o'])); | ||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file1.test.j/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
}); | ||
|
||
test('onlyChanged in config is overwritten by --all or testPathPattern', () => { | ||
|
@@ -100,7 +97,7 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { | |
); | ||
|
||
({stderr} = runJest(DIR, ['--lastCommit'])); | ||
expect(stderr).toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
|
||
writeFiles(DIR, { | ||
'__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, | ||
|
@@ -111,9 +108,9 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { | |
|
||
({stderr} = runJest(DIR)); | ||
|
||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
|
||
run(`${GIT} add .`, DIR); | ||
run(`${GIT} commit -m "second"`, DIR); | ||
|
@@ -123,22 +120,22 @@ test('onlyChanged in config is overwritten by --all or testPathPattern', () => { | |
|
||
({stderr, stdout} = runJest(DIR, ['file2.test.js'])); | ||
expect(stdout).not.toMatch('No tests found related to files'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch('1 total'); | ||
|
||
writeFiles(DIR, { | ||
'file2.js': 'module.exports = {modified: true}', | ||
}); | ||
|
||
({stderr} = runJest(DIR)); | ||
expect(stderr).not.toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
|
||
({stderr} = runJest(DIR, ['--all'])); | ||
expect(stderr).toMatch('PASS __tests__/file1.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
}); | ||
|
||
test('gets changed files for hg', async () => { | ||
|
@@ -173,7 +170,7 @@ test('gets changed files for hg', async () => { | |
}); | ||
|
||
({stdout, stderr} = runJest(DIR, ['-o'])); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
|
||
run(`${HG} add .`, DIR); | ||
run(`${HG} commit -m "test2"`, DIR); | ||
|
@@ -183,10 +180,49 @@ test('gets changed files for hg', async () => { | |
}); | ||
|
||
({stdout, stderr} = runJest(DIR, ['-o'])); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).not.toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
|
||
({stdout, stderr} = runJest(DIR, ['-o', '--changedFilesWithAncestor'])); | ||
expect(stderr).toMatch('PASS __tests__/file2.test.js'); | ||
expect(stderr).toMatch('PASS __tests__/file3.test.js'); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
}); | ||
|
||
test('path on Windows is case-insensitive', () => { | ||
if (process.platform !== 'win32') { | ||
// This test is Windows specific, skip it on other platforms. | ||
return; | ||
} | ||
|
||
const modifiedDIR = path.resolve(DIR, 'outer_dir', 'inner_dir'); | ||
const incorrectModifiedDIR = path.resolve(DIR, 'OUTER_dir', 'inner_dir'); | ||
let stderr; | ||
let stdout; | ||
|
||
writeFiles(modifiedDIR, { | ||
'.watchmanconfig': '', | ||
'__tests__/file1.test.js': `require('../file1'); test('file1', () => {});`, | ||
'file1.js': 'module.exports = {}', | ||
'package.json': '{}', | ||
}); | ||
|
||
run(`${GIT} init`, modifiedDIR); | ||
run(`${GIT} add .`, modifiedDIR); | ||
run(`${GIT} commit -m "first"`, modifiedDIR); | ||
|
||
({stdout} = runJest(modifiedDIR, ['-o'])); | ||
expect(stdout).toMatch('No tests found related to files'); | ||
|
||
writeFiles(modifiedDIR, { | ||
'__tests__/file2.test.js': `require('../file2'); test('file2', () => {});`, | ||
'__tests__/file3.test.js': `require('../file3'); test('file3', () => {});`, | ||
'file2.js': 'module.exports = {}', | ||
'file3.js': `require('./file2')`, | ||
}); | ||
|
||
({stderr} = runJest(modifiedDIR, ['-o'])); | ||
|
||
expect(stderr).not.toMatch(/PASS __tests__(\/|\\)file1.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file2.test.js/); | ||
expect(stderr).toMatch(/PASS __tests__(\/|\\)file3.test.js/); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -141,6 +141,15 @@ const getProjectListFromCLIArgs = (argv, project: ?Path) => { | |
projects.push(project); | ||
} | ||
|
||
if (!projects.length && process.platform === 'win32') { | ||
try { | ||
projects.push(process.binding('fs').realpath(process.cwd())); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. fs.realpathSync() does not correct the path. They differ:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Huh, that's weird There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If I understand it correctly There is a PR, which should expose |
||
} catch (err) { | ||
// do nothing, just catch error | ||
// process.binding('fs').realpath can throw, e.g. on mapped drives | ||
} | ||
} | ||
|
||
if (!projects.length) { | ||
projects.push(process.cwd()); | ||
} | ||
|
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.
can we do
const filePath = fileOrPath.split(path.posix.sep);
here? (or justfileOrPath.split('/')
)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.
Thanks for suggestion. Changed to
const filePath = fileOrPath.split('/')