-
Notifications
You must be signed in to change notification settings - Fork 249
Use Jest as test runner #744
Conversation
Well, there are 2 integration tests in |
Help wanted: So I have a test file that execute phenomic cli here That script has But when I run the test, it throws error about Syntax Error on spread operator https://travis-ci.org/MoOx/phenomic/jobs/159970393#L744-L751 I can run that external script manually without a problem So my question is: Does Jest interfere with babel-register or something ? To reproduce the error message:
|
No you cannot. Just duplicate again to "test". if you move to global conf, this will make duplicate for webpack-*. I have written a blog post about this mess, will publish this soon ;) |
Hum. If that is the case, it's really a mess. Babel should have an option that allow us to choose when and when not to extend babel config. FYI, I'll set NODE_ENV to development than ;) |
You can duplicate, it's just for us, this won't affect docs & boilerplate setup. ANyway it's just a 3 lines section. |
Yeah. I see. Now that problem was fixed, we have a bigger problem.
Bed time, will look in the in tmr. |
72ffbea
to
d7030ba
Compare
All's green (local). Ready for review. Now I can run the hold test suite without freezing my PC. |
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.
I have made some comment but I will need to do that in multiple passes as it's too huge. I don't like expect api at all and I think we should do this using all api to minimize diff. We are going to miss something and I don't want that :(
@@ -13,7 +13,7 @@ coverage | |||
lib | |||
|
|||
# tests results | |||
**/__tests__/_output* | |||
**/__tests__/output* |
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 you do the opposite?
@@ -0,0 +1,2 @@ | |||
approvals = 1 | |||
pattern = "(?i):shipit:|:\\+1:|LGTM" |
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.
Please rebase correctly and remove this file (have been removed yesterday)
@@ -1,11 +1,11 @@ | |||
import test from "ava" |
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.
why did you move tests folder? I don't like this name a lot. We might find something better in the future.
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.
This is me trying to make jest run test from this folder only. See jestjs/jest#1696
I'll rename it back
"tests": "ava", | ||
"#integration-tests": "needs this order (index test the build, and cli is cleaning it)", | ||
"integration-tests": "ava __tests__/index.js && ava __tests__/cli.js", | ||
"integration-tests": "jest --config '{\"testRegex\": \"integration-tests\", \"setupTestFrameworkScriptFile\": \"<rootDir>/scripts/jest-framework-setup.js\"}'", |
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.
Not a fan at all of this inline config. We cannot just have a file in this tests folder?
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.
Just realize that jest accept a file path for configuration. Will fix this.
"coverage": "nyc report --reporter=text-lcov | coveralls", | ||
"all-tests": "cross-env TESTING=1 jest --coverage", | ||
"postall-tests": "npm run test-phenomic-theme-base && npm run docs", | ||
"test": "cross-env TESTING=1 jest", |
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.
Maybe we should rely on NODE_ENV=test instead of TESTING
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.
Agreed
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.
There is 1 problem with using NODE_ENV=test. The configurator changes NODE_ENV when we use --production
flag. And it kills jest
@@ -31,8 +31,6 @@ test("don't break if there is nothing to transform", async (t) => { | |||
}) | |||
|
|||
test("writeAllHTMLFiles", (t) => { | |||
t.plan(3) | |||
|
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.
You cannot just remove that. We need to be sure all assertions are called.
routesToUrls(routesNoMatches, collection, { log }) | ||
|
||
expect(log).toBeCalled() | ||
expect(log.mock.calls[0][0]).toContain( |
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.
That's why I don't like expect. This make us too relying on the test framework :'(
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.
We can pull in expect from npm or chai if you prefer. Jest works great with them. But I am not sure about pretty diff.
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.
I would prefer to get a similar api as what we have currently. jest-ava-api might be still used and improved :)
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.
Hum... What are you suggesting? AVA doesn't have this built-in. We used sinon for this job.
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.
Here for example, we were passing a callback directly. No need to use jest mock since you can pass a log function. I am just not sure how to handle the t.plan pattern.
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.
Yup. We need t.plan or similar to do callback testing like this
@@ -25,7 +25,7 @@ test("should have action to handle get", async (t) => { | |||
}) | |||
|
|||
test("should have action to handle refresh", async (t) => { | |||
t.plan(3) | |||
// t.plan(3) |
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.
Not an an option. We need to handle that somehow.
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.
Yup. That's why I commented out instead of deleted it
|
||
import * as module from "../pages" | ||
import reducer from "../pages" | ||
|
||
process.env.PHENOMIC_USER_PATHNAME = "/" | ||
|
||
test("should have action to handle get", async (t) => { | ||
t.plan(3) | ||
// t.plan(3) |
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.
Not an an option. We need to handle that somehow.
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.
Yup. That's why I commented out instead of deleted it
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.
There is no reference in Jest's docs for this kind of validation.
} | ||
}) | ||
// t.plan(2+5) // 2, err, warn, 5 => array | ||
// t.end() |
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.
How is this check made?
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.
Yup. That's why I commented out instead of deleted it
t.pass() | ||
t.end() | ||
} | ||
describe("bin > commands > setup > inquirer", () => { |
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.
are describe mandatory? What are they for?
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.
nope. I removed them
routesToUrls(routesNoMatches, collection, { log }) | ||
|
||
expect(log).toBeCalled() | ||
expect(log.mock.calls[0][0]).toContain( |
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.
Here for example, we were passing a callback directly. No need to use jest mock since you can pass a log function. I am just not sure how to handle the t.plan pattern.
e8e0f0f
to
41b25c3
Compare
I gave up on this branch. If you take this over, check out |
I am finishing this. |
c13d849
to
2d40339
Compare
dfba0de
to
1ee2185
Compare
I don't like having to add a babel env test section in base theme but I will find a way to hide all this config behind a preset before cutting a release. |
WARNING: Huge diffs