-
-
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
Allow config.transform[regex] to be a function for jest.runCLI(config) #7398
Closed
Closed
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ca97ebf
add support for argv.config as an object to readConfig
jharris4 2d27b56
only normalize config.transform if it is a string
jharris4 100017e
preprocess using the transform if it is a function else require it
jharris4 a48205a
add normalize unit tests for transform as a function
jharris4 61e9fdd
fix formatting for lint / flow
jharris4 40f39f7
add unit test for preprocessor transform as a function vs filepath
jharris4 848585f
guard against customJSTransformer.includes is not a function error
jharris4 3bb6d6e
add unit test for runCLI function with standalone config argument
jharris4 bbf105e
remove typo added to make a passing test fail
jharris4 6f9d9cf
cosmetic - prettier formatting
jharris4 829d5da
add required facebook headers for text fixture files
jharris4 565c83b
fix test assertion by sorting keys before comparing equality
jharris4 e30e7b7
update snapshot for script_transformer_test
jharris4 4667163
remove outdated snapshot for script_transformer_test
jharris4 4ae1e95
cli/run function - add param for optional exit and return results
jharris4 42e1cd2
add tests calling jest-cli run() with string vs object parameters
jharris4 bd032a6
remove run exit parameter and add better error message when yargs throws
jharris4 3aa417a
split run & runCLI tests and cleanup console output for nested tests
jharris4 458bb67
misc lint fixes
jharris4 f7fccaa
rename variable
jharris4 4aa187e
lint fixes for run function returning results
jharris4 df6adfd
fix flow error on run function
jharris4 e48fd77
always mock process.exit for cli run function tests
jharris4 3791c47
Update packages/jest-cli/src/cli/index.js
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
toReplace: 1, | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/jest-cli/src/__tests__/__fixtures__/run/aFile_spec.js
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,18 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require('expect'); | ||
const aFile = require('./aFile'); | ||
|
||
describe('aFile test', () => { | ||
it('should have transformed aFile', () => { | ||
expect(JSON.stringify(aFile)).toEqual(JSON.stringify({runReplaced: 1})); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/jest-cli/src/__tests__/__fixtures__/run/transform-module.js
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,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
process: (src, filename) => src.replace('toReplace', 'runReplaced'), | ||
}; |
13 changes: 13 additions & 0 deletions
13
packages/jest-cli/src/__tests__/__fixtures__/runCLI/aFile.js
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,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
toReplace: 1, | ||
}; |
18 changes: 18 additions & 0 deletions
18
packages/jest-cli/src/__tests__/__fixtures__/runCLI/aFile_spec.js
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,18 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
const expect = require('expect'); | ||
const aFile = require('./aFile'); | ||
|
||
describe('aFile test', () => { | ||
it('should have transformed aFile', () => { | ||
expect(JSON.stringify(aFile)).toEqual(JSON.stringify({runCLIReplaced: 1})); | ||
}); | ||
}); |
13 changes: 13 additions & 0 deletions
13
packages/jest-cli/src/__tests__/__fixtures__/runCLI/transform-module.js
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,13 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
module.exports = { | ||
process: (src, filename) => src.replace('toReplace', 'runCLIReplaced'), | ||
}; |
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,99 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import path from 'path'; | ||
import {run} from '../../cli'; | ||
|
||
const runProject = path.join(__dirname, '../__fixtures__/run'); | ||
|
||
jest.mock('exit'); | ||
|
||
const runArgvString = [ | ||
'--config', | ||
JSON.stringify({ | ||
rootDir: runProject, | ||
testMatch: ['<rootDir>/*_spec.js'], | ||
transform: { | ||
'^.+\\.jsx?$': './transform-module', | ||
}, | ||
}), | ||
]; | ||
|
||
const runArgvObject = [ | ||
'--config', | ||
{ | ||
rootDir: runProject, | ||
testMatch: ['<rootDir>/*_spec.js'], | ||
transform: { | ||
'^.+\\.jsx?$': './transform-module', | ||
}, | ||
}, | ||
]; | ||
|
||
const processOnFn = process.on; | ||
const processExitFn = process.exit; | ||
const processErrWriteFn = process.stderr.write; | ||
const consoleErrorFn = console.error; | ||
|
||
const noSubTestLogs = true; | ||
|
||
describe('run', () => { | ||
beforeEach(() => { | ||
process.on = jest.fn(); | ||
process.on.mockReset(); | ||
process.exit = jest.fn(); | ||
process.exit.mockReset(); | ||
if (noSubTestLogs) { | ||
process.stderr.write = jest.fn(); | ||
process.stderr.write.mockReset(); | ||
console.error = jest.fn(); | ||
console.error.mockReset(); | ||
} | ||
}); | ||
|
||
afterEach(() => { | ||
process.on = processOnFn; | ||
process.exit = processExitFn; | ||
if (noSubTestLogs) { | ||
process.stderr.write = processErrWriteFn; | ||
console.error = consoleErrorFn; | ||
} | ||
}); | ||
|
||
describe('config as string', () => { | ||
it('passes the test when the config has a transform module path', async () => { | ||
let runResult = null; | ||
let error = null; | ||
try { | ||
runResult = await run(runArgvString, runProject); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
const numPassedTests = runResult ? runResult.numPassedTests : -1; | ||
expect(error).toBe(null); | ||
expect(numPassedTests).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('config as object', () => { | ||
it('throws running the test when the config is an object', async () => { | ||
let runResult = null; | ||
let error = null; | ||
try { | ||
runResult = await run(runArgvObject, runProject); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
const numPassedTests = runResult ? runResult.numPassedTests : -1; | ||
expect(error).not.toBe(null); | ||
expect(numPassedTests).toBe(-1); | ||
}); | ||
}); | ||
}); |
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,84 @@ | ||
/** | ||
* Copyright (c) 2014-present, Facebook, Inc. 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. | ||
* | ||
*/ | ||
|
||
'use strict'; | ||
|
||
import path from 'path'; | ||
import {runCLI} from '../../cli'; | ||
import transformModule from '../__fixtures__/runCLI/transform-module'; | ||
|
||
const project = path.join(__dirname, '../__fixtures__/runCLI'); | ||
const projects = [project]; | ||
|
||
const argvObject = { | ||
config: { | ||
testMatch: ['<rootDir>/*_spec.js'], | ||
transform: { | ||
'^.+\\.jsx?$': () => transformModule, | ||
}, | ||
}, | ||
}; | ||
|
||
const argvString = { | ||
config: JSON.stringify({ | ||
rootDir: project, | ||
testMatch: ['<rootDir>/*_spec.js'], | ||
transform: { | ||
'^.+\\.jsx?$': './transform-module', | ||
}, | ||
}), | ||
}; | ||
|
||
const processErrWriteFn = process.stderr.write; | ||
|
||
const noSubTestLogs = true; | ||
|
||
describe('runCLI', () => { | ||
beforeEach(() => { | ||
if (noSubTestLogs) { | ||
process.stderr.write = jest.fn(); | ||
process.stderr.write.mockReset(); | ||
} | ||
}); | ||
|
||
afterEach(() => { | ||
if (noSubTestLogs) { | ||
process.stderr.write = processErrWriteFn; | ||
} | ||
}); | ||
|
||
describe('config as object', () => { | ||
it('passes the test when the config has a transform function', async () => { | ||
let runResult = null; | ||
let error = null; | ||
try { | ||
runResult = await runCLI(argvObject, projects); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
const numPassedTests = runResult ? runResult.results.numPassedTests : -1; | ||
expect(error).toBe(null); | ||
expect(numPassedTests).toBe(1); | ||
}); | ||
}); | ||
|
||
describe('config as string', () => { | ||
it('passes the test when the config is a string', async () => { | ||
let runResult = null; | ||
let error = null; | ||
try { | ||
runResult = await runCLI(argvString, projects); | ||
} catch (ex) { | ||
error = ex; | ||
} | ||
const numPassedTests = runResult ? runResult.results.numPassedTests : -1; | ||
expect(error).toBe(null); | ||
expect(numPassedTests).toBe(1); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.
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.