-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
https://github.com/kentcdodds/kcd-scripts/blob/main/src/scripts/test.js with minor modifications
- Loading branch information
1 parent
dfafeac
commit c729d12
Showing
18 changed files
with
533 additions
and
33 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
const { jest } = require('./src/config') | ||
|
||
module.exports = { | ||
...jest, | ||
coverageThreshold: { | ||
global: { | ||
branches: 33, | ||
functions: 50, | ||
lines: 48, | ||
statements: 48, | ||
}, | ||
}, | ||
} |
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 @@ | ||
module.exports = require('./src/config/jest.config') |
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,3 @@ | ||
module.exports = { | ||
sync: jest.fn(() => ({ status: 0 })), | ||
} |
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,48 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`format calls node with the script path and args including inspect-brk argument: format script 1`] = `node --inspect-brk=3080 <PROJECT_ROOT>/src/scripts/test.js --no-watch`; | ||
exports[`format calls node with the script path and args: format script 1`] = `node <PROJECT_ROOT>/src/scripts/test.js --no-watch`; | ||
exports[`format does not log for other signals: format signal 1`] = `Array []`; | ||
exports[`format logs for SIGKILL signal: format signal 1`] = ` | ||
Array [ | ||
Array [ | ||
The script "lint" failed because the process exited too early. This probably means the system ran out of memory or someone called \`kill -9\` on the process., | ||
], | ||
] | ||
`; | ||
exports[`format logs for SIGTERM signal: format signal 1`] = ` | ||
Array [ | ||
Array [ | ||
The script "build" failed because the process exited too early. Someone might have called \`kill\` or \`killall\`, or the system could be shutting down., | ||
], | ||
] | ||
`; | ||
exports[`format logs help with no args: format snapshotLog 1`] = ` | ||
Array [ | ||
Array [ | ||
Usage: ../ [script] [--flags] | ||
Available Scripts: | ||
build | ||
format | ||
lint | ||
test | ||
typecheck | ||
validate | ||
Options: | ||
All options depend on the script. Docs will be improved eventually, but for most scripts you can assume that the args you pass will be forwarded to the respective tool that's being run under the hood. | ||
May the force be with you. | ||
, | ||
], | ||
] | ||
`; | ||
exports[`format throws unknown script: format error 1`] = `Unknown script "unknown-script".`; |
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,27 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`getConcurrentlyArgs gives good args to pass to concurrently 1`] = ` | ||
Array [ | ||
--kill-others-on-fail, | ||
--prefix, | ||
[{name}], | ||
--names, | ||
build,lint,test,validate,a,b,c,d,e,f,g,h,i,j, | ||
--prefix-colors, | ||
bgBlue.bold.white,bgGreen.bold.white,bgMagenta.bold.white,bgCyan.bold.white,bgWhite.bold.white,bgRed.bold.white,bgBlack.bold.white,bgYellow.bold.white,bgBlue.bold.white,bgGreen.bold.white,bgMagenta.bold.white,bgCyan.bold.white,bgWhite.bold.white,bgRed.bold.white, | ||
"echo build", | ||
"echo lint", | ||
"echo test", | ||
"echo validate", | ||
"echo a", | ||
"echo b", | ||
"echo c", | ||
"echo d", | ||
"echo e", | ||
"echo f", | ||
"echo g", | ||
"echo h", | ||
"echo i", | ||
"echo j", | ||
] | ||
`; |
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,87 @@ | ||
import path from 'path' | ||
import slash from 'slash' | ||
import cases from 'jest-in-case' // TODO: replace jest-in-case with test.each() | ||
|
||
const projectRoot = path.join(__dirname, '../../') | ||
|
||
expect.addSnapshotSerializer({ | ||
print: (val) => slash(val.replace(projectRoot, '<PROJECT_ROOT>/')), | ||
test: (val) => typeof val === 'string' && val.includes(projectRoot), | ||
}) | ||
|
||
cases( | ||
'format', | ||
({ snapshotLog = false, throws = false, signal = false, args = [] }) => { | ||
// beforeEach | ||
const { sync: crossSpawnSyncMock } = require('cross-spawn') | ||
const originalExit = process.exit | ||
const originalArgv = process.argv | ||
const originalLog = console.log | ||
process.exit = jest.fn() | ||
console.log = jest.fn() | ||
try { | ||
// tests | ||
process.argv = ['node', '../', ...args] | ||
crossSpawnSyncMock.mockClear() | ||
if (signal) { | ||
crossSpawnSyncMock.mockReturnValueOnce({ result: 1, signal }) | ||
} | ||
require('..') | ||
if (snapshotLog) { | ||
expect(console.log.mock.calls).toMatchSnapshot('format snapshotLog') | ||
} else if (signal) { | ||
expect(process.exit).toHaveBeenCalledTimes(1) | ||
expect(process.exit).toHaveBeenCalledWith(1) | ||
expect(console.log.mock.calls).toMatchSnapshot('format signal') | ||
} else { | ||
expect(crossSpawnSyncMock).toHaveBeenCalledTimes(1) | ||
const [firstCall] = crossSpawnSyncMock.mock.calls | ||
const [script, calledArgs] = firstCall | ||
expect([script, ...calledArgs].join(' ')).toMatchSnapshot( | ||
'format script' | ||
) | ||
} | ||
} catch (error) { | ||
if (throws) { | ||
expect(error.message).toMatchSnapshot('format error') | ||
} else { | ||
throw error | ||
} | ||
} finally { | ||
// afterEach | ||
process.exit = originalExit | ||
process.argv = originalArgv | ||
console.log = originalLog | ||
jest.resetModules() | ||
} | ||
}, | ||
{ | ||
'calls node with the script path and args': { | ||
args: ['test', '--no-watch'], | ||
}, | ||
'calls node with the script path and args including inspect-brk argument': { | ||
args: ['--inspect-brk=3080', 'test', '--no-watch'], | ||
}, | ||
'throws unknown script': { | ||
args: ['unknown-script'], | ||
throws: true, | ||
}, | ||
'logs help with no args': { | ||
snapshotLog: true, | ||
}, | ||
'logs for SIGKILL signal': { | ||
args: ['lint'], | ||
signal: 'SIGKILL', | ||
}, | ||
'logs for SIGTERM signal': { | ||
args: ['build'], | ||
signal: 'SIGTERM', | ||
}, | ||
'does not log for other signals': { | ||
args: ['test'], | ||
signal: 'SIGBREAK', | ||
}, | ||
} | ||
) | ||
|
||
/* eslint complexity:0 */ |
Oops, something went wrong.