-
Notifications
You must be signed in to change notification settings - Fork 2
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
CPP-733 Jest plugin #160
CPP-733 Jest plugin #160
Conversation
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.
A few nitpicks but this all looks good imo!
core/sandbox/package.json
Outdated
@@ -34,7 +34,10 @@ | |||
"@dotcom-tool-kit/node": "file:../../plugins/node" | |||
}, | |||
"husky": { | |||
"pre-commit": "dotcom-tool-kit git:precommit" | |||
"pre-commit": "dotcom-tool-kit git:precommit", |
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.
suggestion: this line can now be safely deleted after #157
"pre-commit": "dotcom-tool-kit git:precommit", |
plugins/jest/package.json
Outdated
"license": "ISC", | ||
"dependencies": { | ||
"@dotcom-tool-kit/types": "file:../../lib/types", | ||
"jest-cli": "^27.4.7" |
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.
question: would it be better to have jest-cli
as a peer dependency so that the consumer can use their own copy? we aren't consistent with this at the moment
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.
great suggestion 👍
plugins/jest/src/run-jest.ts
Outdated
if (code === 0) { | ||
resolve() | ||
} else { | ||
reject(new Error(`Jest returned an error`)) |
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.
nitpick: we should only throw ToolKitError
from our code
reject(new Error(`Jest returned an error`)) | |
reject(new ToolKitError(`Jest returned an error`)) |
plugins/jest/src/run-jest.ts
Outdated
|
||
const jestCLIPath = require.resolve('jest-cli/bin/jest') | ||
|
||
export default function runJest(mode: string, options: JestOptions) : Promise<void> { |
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.
nitpick: we should limit the mode type to the two possible string literals it is allowed to be
export default function runJest(mode: string, options: JestOptions) : Promise<void> { | |
type JestMode = "ci" | "local" | |
export default function runJest(mode: JestMode, options: JestOptions) : Promise<void> { |
@@ -17,7 +17,7 @@ console.log('📦 initialising package') | |||
execSync('npm init -y --scope @dotcom-tool-kit') | |||
|
|||
console.log('📥 installing dependencies') | |||
execSync('npm install ../task') | |||
execSync('npm install ../../lib/types') |
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.
praise: nice catch!
|
||
jest.mock('child_process', () => ({ | ||
fork: jest.fn(() => { | ||
// return a fake emitter that immediately sends an "exit" event, so the webpack task resolves |
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.
nitpick: copy and paste error 😄
// return a fake emitter that immediately sends an "exit" event, so the webpack task resolves | |
// return a fake emitter that immediately sends an "exit" event, so the jest task resolves |
There is no well documented way run jest programmatically (issue) so I have used the cli to run jest