Code Monkey home page Code Monkey logo

Comments (4)

simondel avatar simondel commented on July 16, 2024

Existing projects such as grunt-mocha-test can be used as reference.
The Mocha API can also be viewed in the Mocha source

from stryker-js.

simondel avatar simondel commented on July 16, 2024

We only copy the source files of a project to a different location to run the tests. This can cause issues when files are linked to each other using require statements that have relative paths. Since the test files are not copied, they will still require the original source files, instead of the copy.

from stryker-js.

nicojs avatar nicojs commented on July 16, 2024

Wow! Nice find. This is indeed a problem.

The way i see it: we have 2 possibilities

  1. Override the global require function. Then, if a require call is made, we forward it to the original require directly, unless it starts with . or .., in that case we rewire the require to the sand-boxed version of the file.
  2. We just include the test files in the sandbox.

The second solution is safest but comes with a performance overhead.

The first solution is very error prone. For example:

  1. As part of the unit test, the user can use something like Mockery or Rewire to override the global require themselves. This might not be a problem, but we'll have to test it anyway.
  2. How do we distinguish between a require statement from the unit test framework and the production code. I might require something like '../../src/MySystemUnderTest' (clearly should be rewired to the sandbox version), but it could also be something like '../mocks/MockHelper' (clearly not to be rewired)
  3. We also use require to make our code work. That one will also be the rewired one. We need to make sure this doesn't break anything.

I would go for the second solution for now, as it is safer. We can later change it if we want to optimize for performance.

from stryker-js.

simondel avatar simondel commented on July 16, 2024

https://github.com/stryker-mutator/stryker-mocha-runner

from stryker-js.

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.