From b6611c79c0df55d6d9575ba3bd026f8cce00d1a0 Mon Sep 17 00:00:00 2001 From: jamesgeorge007 Date: Thu, 26 Nov 2020 13:26:30 +0530 Subject: [PATCH] test(cli): use it.each to improve test run output --- lib/cli/package.json | 2 +- lib/cli/test/commands/init.test.js | 24 ++++++++++-------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/lib/cli/package.json b/lib/cli/package.json index 7fd0248bcbd4..b814f7c6460c 100644 --- a/lib/cli/package.json +++ b/lib/cli/package.json @@ -33,7 +33,7 @@ ], "scripts": { "prepare": "node ../../scripts/prepare.js && node ./scripts/generate-sb-packages-versions.js", - "test": "jest test/**/*.test.js", + "test": "jest test/**/*.test.js --verbose", "postversion": "node ./scripts/generate-sb-packages-versions.js" }, "dependencies": { diff --git a/lib/cli/test/commands/init.test.js b/lib/cli/test/commands/init.test.js index 4e94c0a74204..2f190c0b6d16 100644 --- a/lib/cli/test/commands/init.test.js +++ b/lib/cli/test/commands/init.test.js @@ -8,12 +8,12 @@ const fixturesDirPath = path.join(__dirname, '..', 'fixtures'); const runDirPath = path.join(__dirname, '..', 'run'); const rootPath = path.join(__dirname, '..', '..', '..', '..'); +const dirs = fs.readdirSync(fixturesDirPath); beforeAll(() => { fse.removeSync(runDirPath); fse.mkdirSync(runDirPath); // Copy all files from fixtures directory to `run` - const dirs = fs.readdirSync(fixturesDirPath); dirs.forEach((dir) => { const src = path.join(fixturesDirPath, dir); const dest = path.join(runDirPath, path.basename(src)); @@ -26,29 +26,25 @@ afterAll(() => { }); describe('sb init', () => { - it('starts storybook without errors', () => { - const dirs = fs.readdirSync(runDirPath); + beforeAll(() => { dirs.forEach((dir) => { run(['init', '--skip-install', 'yes'], { cwd: path.join(runDirPath, dir) }); }); // Install all the dependencies in a single run - console.log('Running bootstrap'); run( ['yarn', 'install', '--non-interactive', '--silent', '--pure-lockfile'], { cwd: rootPath }, false ); - + }); + it.each(dirs)('starts storybook in smoke-test mode for: %s', (dir) => { // Check that storybook starts without errors - dirs.forEach((dir) => { - console.log(`Running smoke test in ${dir}`); - const { status } = run( - ['yarn', 'storybook', '--smoke-test', '--quiet'], - { cwd: path.join(runDirPath, dir) }, - false - ); - expect(status).toBe(0); - }); + const { status } = run( + ['yarn', 'storybook', '--smoke-test', '--quiet'], + { cwd: path.join(runDirPath, dir) }, + false + ); + expect(status).toBe(0); }); });