mercredi 13 juin 2018

Testing javascript library with with building/packaging included

Let's say I'm writing a javascript library for use in node.js. The lib source (say, folder /src) goes through some transformation (ex: babel) and the generated output is saved on /dist. Im using jest for testing.

In the most common testing setups I see around, the test files require the functions to be tested from the project folders themselves. Example:

|
|__ someFolder
  |__ source.js
  |__ source.test.js

In source.test.js

// source.test.js
const lib = require('./source')
test('test me', () => {
   //...
})

While this is fine, recently the lib had a problem introduced by the compiling process which I can't test with this setup. I'd like to test the lib as if it was required by another consumer module, instead of just doing relative requires, so that the packaging is also tested. Is there a recommended way I would do that?

Aucun commentaire:

Enregistrer un commentaire