This chapter provides the user with all needed information around testing within this project.
As testing framework we are currently using Jest.
Since the CLI is mainly reading and writing files, the tests are using the mock-fs module to allow Node's built-in fs module to be backed temporarily by an in-memory, mock file system. This lets you run tests against a set of mock files and directories instead of lugging around a bunch of test fixtures.
The CLI will be most probably used also in CI/CD pipelines. Therefore the process exit-codes are very important. The jest-mock-process module mocks the Node's process properties in Jest making them easily testable.
We don't use any specific testing strategy.
We highly recommend to use the following beforeEach/afterEach script to mock the fs and the process module and to instantiate the command:
afterEach(() => {
mockFs.restore();
mockExit.mockRestore();
mockStdout.mockRestore();
mockStderr.mockRestore();
mockLog.mockRestore();
});
beforeEach(() => {
mockExit = mockProcessExit();
mockStdout = mockProcessStdout();
mockStderr = mockProcessStderr();
mockLog = mockConsoleLog();
mockFs({
fake_test_folder: {},
"src/docs": mockFs.load(path.resolve("src/docs"), {
lazy: false,
}),
"src/root": mockFs.load(path.resolve("src/root"), {
lazy: false,
}),
});
install = new Install({
basePath: "fake_test_folder",
...configuration,
moduleBasePath: path.join(".", "src"),
packageVersion: "1.0.0",
});
});
Local Setup:
$ git clone https://git.sinnerschrader.com/deven/documentation-skeleton.git
$ cd documentation-skeleton
$ npm install
The project test suite is run with
$ npm run test