GithubHelp home page GithubHelp logo

Comments (13)

xfumihiro avatar xfumihiro commented on May 21, 2024 1

@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.

xfumihiro avatar xfumihiro commented on May 21, 2024

@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.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

@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.

xfumihiro avatar xfumihiro commented on May 21, 2024

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.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

@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.

yq314 avatar yq314 commented on May 21, 2024

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.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

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.

yq314 avatar yq314 commented on May 21, 2024

@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.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

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.

yq314 avatar yq314 commented on May 21, 2024

That's a good idea indeed!

from differencify.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

Do you mind adding a PR for that?

from differencify.

yq314 avatar yq314 commented on May 21, 2024

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.

NimaSoroush avatar NimaSoroush commented on May 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.