Browse Source

build: fix dom snapshot config

using svelte format for stories requires storybook to run with the
--index-json flag but this breaks the storage location of DOM
snapshots

the configuration files in this commit fixes this and also moves them
to the same location as the image snapshots
master
DanConwayDev 2 years ago
parent
commit
9efb43e0d2
No known key found for this signature in database
GPG Key ID: 68E15486D73F75E1
  1. 1
      .storybook/test-runner.ts
  2. 6
      __snapshots__/navbar.test.js.snap
  3. 13
      test-runner-jest.config.js
  4. 9
      test-runner-snapshotresolver.js

1
.storybook/test-runner.ts

@ -15,6 +15,7 @@ const config: TestRunnerConfig = { @@ -15,6 +15,7 @@ const config: TestRunnerConfig = {
const innerHTML = await elementHandler.innerHTML();
expect(innerHTML).toMatchSnapshot();
}
else throw "cannot find storybook DOM root to take DOM screenshot"
// Image Snapshop
const image = await page.screenshot();
expect(image).toMatchImageSnapshot({

6
src/lib/components/__snapshots__/Navbar.stories.ts.snap → __snapshots__/navbar.test.js.snap

@ -1,6 +1,6 @@ @@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`Navbar Default smoke-test 1`] = `
exports[`Navbar Default test 1`] = `
<div class="navbar bg-neutral">
<div class="flex-1">
<h4>
@ -26,7 +26,7 @@ exports[`Navbar Default smoke-test 1`] = ` @@ -26,7 +26,7 @@ exports[`Navbar Default smoke-test 1`] = `
</div>
`;
exports[`Navbar NIP07Exists smoke-test 1`] = `
exports[`Navbar NIP07Exists test 1`] = `
<div class="navbar bg-neutral">
<div class="flex-1">
<h4>
@ -49,7 +49,7 @@ exports[`Navbar NIP07Exists smoke-test 1`] = ` @@ -49,7 +49,7 @@ exports[`Navbar NIP07Exists smoke-test 1`] = `
</div>
`;
exports[`Navbar NoNIP07 smoke-test 1`] = `
exports[`Navbar NoNIP07 test 1`] = `
<div class="navbar bg-neutral">
<div class="flex-1">
<h4>

13
test-runner-jest.config.js

@ -0,0 +1,13 @@ @@ -0,0 +1,13 @@
const { getJestConfig } = require('@storybook/test-runner');
const path = require('path');
/**
* @type {import('@jest/types').Config.InitialOptions}
*/
module.exports = {
// The default configuration comes from @storybook/test-runner
...getJestConfig(),
/** Add your own overrides below
* @see https://jestjs.io/docs/configuration
*/
snapshotResolver: "<rootDir>/test-runner-snapshotresolver.js"
};

9
test-runner-snapshotresolver.js

@ -0,0 +1,9 @@ @@ -0,0 +1,9 @@
const path = require('path');
module.exports = {
resolveSnapshotPath: (testPath, snapshotExtension) =>
path.join(process.cwd(), '__snapshots__', path.basename(testPath) + snapshotExtension),
resolveTestPath: (snapshotFilePath, snapshotExtension) =>
path.join(process.env.TEST_ROOT, path.basename(snapshotFilePath, snapshotExtension)),
testPathForConsistencyCheck: path.join(process.env.TEST_ROOT, 'example.test.js'),
};
Loading…
Cancel
Save