Comments (13)
@NimaSoroush If you want to launch/close puppeteer once upon all test suites in Jest, you should do that inside Global setup/teardown scripts (not inside test environments as I've explained here)
from differencify.
@NimaSoroush do you want differencify to act as a Jest plugin, which is what jest-puppeteer-example is trying to do. If so, then it won't support other test frameworks.
from differencify.
@xfumihiro : Differencify is independent to test framework and it could be integrated with any test runner, but my goal is to optimise for Jest. As you can see I've added special functionalities for Jest like custom matcher
.
I can look into integrating other test runners (e.g. Mocha, Jasmine, ...) in future if any feature request came, but current AFAIK all users of this lib are Jest runners.
So what I want to achieve as part of this card is to avoid launchBrowser
and cleanup
call for Jest users. Does that make sense?
from differencify.
AFAIK Jest handles test suite runtimes differently than others so I had to make these PRs
(Add Global Setup/Teardown options, Add Async Test Environment APIs) to make it work with global hooks.
It would make sense if Differencify is split up as core & adapters.
from differencify.
@xfumihiro : I like the idea of splitting Differencify into core & adapters 👍
I think it should be enough for jest to expose the CustomEnvironment
and user could just use it in package.json
or jest.config.js
. Something like
// jest.config.js
import Differencify, { JestEnvironment } from 'differencify';
module.exports = JestEnvironment;
or
// package.json
...
"jest": {
"testEnvironment": "/node_modules/differencify/dist/JestEnvironment.js"
},
...
That should be enough. right?
from differencify.
Hi @NimaSoroush I'm Qing, I found out the cause of the issue I reported to you earlier over slack: when Differencify is instantiated in a sub class of NodeEnvironment, it can't access expect
for some reason. So the isJest()
call returns false
and the tests are run in valina node mode (test names are set to test 1
, test 2
etc. and jest-reporter can't insert results into the generated html).
One thing I don't understand is that even though differencity.init()
is called in separate tests it still can't detect expect
, to made it work I had to remove my custom NodeEnvironment and instantiate differencity in the test file.
from differencify.
Hi @yq314 , That is interesting! Is there anything else we can use in NodeEnvironment that would help us with detecting the Jest environment?
from differencify.
@NimaSoroush when it's running in NodeEnvironment or its subclass would indicate that it's already running in jest environment? So we could always set isJest()
to true
?
from differencify.
Yep, but we need an automated way of detecting the environment! another way to tackle this would be to introduce an aditional flag that could manually tell differencify is running on Jest
const differencify = new Differencify({ testRunner: 'jest' });
from differencify.
That's a good idea indeed!
from differencify.
Do you mind adding a PR for that?
from differencify.
I'd love too, but I want to get clarification on something first. As pointed out here #62 (comment) we should do launchBrowser()
and cleanup()
in the global startup and teardown script, however the differencify
instance needs to be created somewhere else, because instance created in global startup script can't be accessed in test scripts.
possible to make differencify
a global instance so I don't need to new
it?
Similar to puppeteer:
const puppeteer = require('puppeteer');
It would be easier if we have:
const differencify = require('differencify');
And in this case we wouldn't need a NodeEnvironment, so the manual setting of isJest
would be unnecessary too.
from differencify.
I have never tried that but that seems to be possible but needs a little bit of extra work. I know puppeteer provides a way of pointing to chrome instance path through browserWSEndpoint
. that might be the way to achieve it. Differencify already support that through lunch options https://github.com/NimaSoroush/differencify/blob/master/src/index.js#L21
Is that something you looking for?
from differencify.
Related Issues (20)
- Multiple teststoMatchSnapShots
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 7
- An in-range update of jimp is breaking the build 🚨 HOT 7
- A mismatchThreshold of zero will always fail.
- Tests pass even when error occurs in tests HOT 1
- An in-range update of eslint-plugin-jsx-a11y is breaking the build 🚨 HOT 2
- Running w/out Jest prevents consistent filenames HOT 4
- An in-range update of eslint is breaking the build 🚨 HOT 7
- An in-range update of babel-eslint is breaking the build 🚨 HOT 1
- An in-range update of jsdoc-to-markdown is breaking the build 🚨 HOT 1
- Differencify appends indexes to a unique generated snapshots' names. HOT 3
- Feature request: partial page comparison HOT 1
- An in-range update of eslint is breaking the build 🚨 HOT 5
- An in-range update of jsdoc-to-markdown is breaking the build 🚨 HOT 1
- An in-range update of eslint-plugin-import is breaking the build 🚨 HOT 4
- Issue with mockRequest(); HOT 1
- An in-range update of babel-eslint is breaking the build 🚨 HOT 1
- An in-range update of jsdoc is breaking the build 🚨 HOT 1
- runtime issues with Puppeteer 8.0
- ReferenceError: GlobalOptions is not defined HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from differencify.