-
Notifications
You must be signed in to change notification settings - Fork 207
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: a few things I can't remember...
- Loading branch information
Kent C. Dodds
committed
Sep 24, 2017
1 parent
39513ae
commit a8c2cd1
Showing
12 changed files
with
240 additions
and
16 deletions.
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
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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`format --no-cache will disable caching 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --no-cache .`; | ||
|
||
exports[`format calls eslint CLI with default args 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache .`; | ||
|
||
exports[`format does not use built-in config with .eslintrc file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`; | ||
|
||
exports[`format does not use built-in config with .eslintrc.js file 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`; | ||
|
||
exports[`format does not use built-in config with --config 1`] = `eslint --ignore-path ./src/config/eslintignore --cache --config ./custom-config.js .`; | ||
|
||
exports[`format does not use built-in config with eslintConfig pkg prop 1`] = `eslint --ignore-path ./src/config/eslintignore --cache .`; | ||
|
||
exports[`format does not use built-in ignore with .eslintignore file 1`] = `eslint --config ./src/config/eslintrc.js --cache .`; | ||
|
||
exports[`format does not use built-in ignore with --ignore-path 1`] = `eslint --config ./src/config/eslintrc.js --cache --ignore-path ./my-ignore .`; | ||
|
||
exports[`format does not use built-in ignore with eslintIgnore pkg prop 1`] = `eslint --config ./src/config/eslintrc.js --cache .`; | ||
|
||
exports[`format runs on given files, but only js files 1`] = `eslint --config ./src/config/eslintrc.js --ignore-path ./src/config/eslintignore --cache ./src/index.js ./src/component.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,21 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`format calls jest.run with default args 1`] = `--config {"builtInConfig":true} --watch`; | ||
|
||
exports[`format does not watch --updateSnapshot 1`] = `--config {"builtInConfig":true} --updateSnapshot`; | ||
|
||
exports[`format does not watch on CI 1`] = `--config {"builtInConfig":true}`; | ||
|
||
exports[`format does not watch on SCRIPTS_PRECOMMIT 1`] = `--config {"builtInConfig":true}`; | ||
|
||
exports[`format does not watch with --coverage 1`] = `--config {"builtInConfig":true} --coverage`; | ||
|
||
exports[`format does not watch with --no-watch 1`] = `--config {"builtInConfig":true} --no-watch`; | ||
|
||
exports[`format forwards args 1`] = `--config {"builtInConfig":true} --coverage --watch`; | ||
|
||
exports[`format uses custom config with --config 1`] = `--watch --config ./my-config.js`; | ||
|
||
exports[`format uses custom config with jest prop in pkg 1`] = `--watch`; | ||
|
||
exports[`format uses custom config with jest.config.js file 1`] = `--watch`; |
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,88 @@ | ||
import cases from 'jest-in-case' | ||
|
||
jest.mock('jest', () => ({run: jest.fn()})) | ||
jest.mock('../../config/jest.config', () => ({builtInConfig: true})) | ||
|
||
// this removes the quotes around strings... | ||
expect.addSnapshotSerializer({ | ||
print: val => val, | ||
test: val => typeof val === 'string', | ||
}) | ||
|
||
cases( | ||
'format', | ||
({ | ||
args = [], | ||
utils = require('../../utils'), | ||
hasPkgProp = () => false, | ||
hasFile = () => false, | ||
setup = () => () => {}, | ||
}) => { | ||
// beforeEach | ||
const {sync: crossSpawnSyncMock} = require('cross-spawn') | ||
const originalArgv = process.argv | ||
const originalExit = process.exit | ||
Object.assign(utils, { | ||
hasPkgProp, | ||
hasFile, | ||
resolveBin: (modName, {executable = modName} = {}) => executable, | ||
}) | ||
process.exit = jest.fn() | ||
const teardown = setup() | ||
|
||
process.argv = ['node', '../lint', ...args] | ||
crossSpawnSyncMock.mockClear() | ||
|
||
try { | ||
// tests | ||
require('../lint') | ||
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1) | ||
const [firstCall] = crossSpawnSyncMock.mock.calls | ||
const [script, calledArgs] = firstCall | ||
expect([script, ...calledArgs].join(' ')).toMatchSnapshot() | ||
} catch (error) { | ||
throw error | ||
} finally { | ||
teardown() | ||
// afterEach | ||
process.exit = originalExit | ||
process.argv = originalArgv | ||
jest.resetModules() | ||
} | ||
}, | ||
{ | ||
'calls eslint CLI with default args': {}, | ||
'does not use built-in config with --config': { | ||
args: ['--config', './custom-config.js'], | ||
}, | ||
'does not use built-in config with .eslintrc file': { | ||
hasFile: filename => filename === '.eslintrc', | ||
}, | ||
'does not use built-in config with .eslintrc.js file': { | ||
hasFile: filename => filename === '.eslintrc.js', | ||
}, | ||
'does not use built-in config with eslintConfig pkg prop': { | ||
hasPkgProp: prop => prop === 'eslintConfig', | ||
}, | ||
'does not use built-in ignore with --ignore-path': { | ||
args: ['--ignore-path', './my-ignore'], | ||
}, | ||
'does not use built-in ignore with .eslintignore file': { | ||
hasFile: filename => filename === '.eslintignore', | ||
}, | ||
'does not use built-in ignore with eslintIgnore pkg prop': { | ||
hasPkgProp: prop => prop === 'eslintIgnore', | ||
}, | ||
'--no-cache will disable caching': { | ||
args: ['--no-cache'], | ||
}, | ||
'runs on given files, but only js files': { | ||
args: [ | ||
'./src/index.js', | ||
'./package.json', | ||
'./src/index.css', | ||
'./src/component.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,88 @@ | ||
import cases from 'jest-in-case' | ||
|
||
jest.mock('jest', () => ({run: jest.fn()})) | ||
jest.mock('../../config/jest.config', () => ({builtInConfig: true})) | ||
|
||
// this removes the quotes around strings... | ||
expect.addSnapshotSerializer({ | ||
print: val => val, | ||
test: val => typeof val === 'string', | ||
}) | ||
|
||
cases( | ||
'format', | ||
({ | ||
args = [], | ||
utils = require('../../utils'), | ||
pkgHasJestProp = false, | ||
hasJestConfigFile = false, | ||
setup = () => () => {}, | ||
ci = 'false', | ||
precommit = 'false', | ||
}) => { | ||
// beforeEach | ||
const {run: jestRunMock} = require('jest') | ||
const originalArgv = process.argv | ||
const prevCI = process.env.CI | ||
const prevPrecommit = process.env.SCRIPTS_PRECOMMIT | ||
process.env.CI = ci | ||
process.env.SCRIPTS_PRECOMMIT = precommit | ||
Object.assign(utils, { | ||
hasPkgProp: () => pkgHasJestProp, | ||
hasFile: () => hasJestConfigFile, | ||
}) | ||
process.exit = jest.fn() | ||
const teardown = setup() | ||
|
||
process.argv = ['node', '../test', ...args] | ||
jestRunMock.mockClear() | ||
|
||
try { | ||
// tests | ||
require('../test') | ||
expect(jestRunMock).toHaveBeenCalledTimes(1) | ||
const [firstCall] = jestRunMock.mock.calls | ||
const [jestArgs] = firstCall | ||
expect(jestArgs.join(' ')).toMatchSnapshot() | ||
} catch (error) { | ||
throw error | ||
} finally { | ||
teardown() | ||
// afterEach | ||
process.argv = originalArgv | ||
process.env.CI = prevCI | ||
process.env.SCRIPTS_PRECOMMIT = prevPrecommit | ||
jest.resetModules() | ||
} | ||
}, | ||
{ | ||
'calls jest.run with default args': {}, | ||
'does not watch on CI': { | ||
ci: 'true', | ||
}, | ||
'does not watch on SCRIPTS_PRECOMMIT': { | ||
precommit: 'true', | ||
}, | ||
'does not watch with --no-watch': { | ||
args: ['--no-watch'], | ||
}, | ||
'does not watch with --coverage': { | ||
args: ['--coverage'], | ||
}, | ||
'does not watch --updateSnapshot': { | ||
args: ['--updateSnapshot'], | ||
}, | ||
'uses custom config with --config': { | ||
args: ['--config', './my-config.js'], | ||
}, | ||
'uses custom config with jest prop in pkg': { | ||
pkgHasJestProp: true, | ||
}, | ||
'uses custom config with jest.config.js file': { | ||
hasJestConfigFile: true, | ||
}, | ||
'forwards args': { | ||
args: ['--coverage', '--watch'], | ||
}, | ||
}, | ||
) |
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
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