I have a CLI tool that is generating files and folders based on command line input. The files and folders are created relative to the location where the script is executed (using process.cwd()
and path.resolve()
).
I am trying to write a system test for it. So I want to execute the entrypoint function with a set of parameters, let the tool generate the files and folders and then test if the output is correct.
I wrote my test like this:
import 'core-js/stable';
import 'regenerator-runtime/runtime';
const generate = require('./generate');
describe('My CLI tool', () => {
test('generates correct output', () => {
const answers = {
option: 'Input',
optionBoolean: false,
// etc.
};
await generate(answers);
// I did not get so far yet
// expect().toEqual();
});
});
The problem that I have now is that when I execute my tests it generates the files and folders relative to the root directory of my CLI tool project.
I also tried creating a directory inside the project (e.g. __temp__
) and then executing the test cases from there but it did not change anything.
I guess that is because the npm script is executed relative to the package.json
?
Aucun commentaire:
Enregistrer un commentaire