From 7c245bcaeeb79d951f3e47aa6be1f24e6da8f9c3 Mon Sep 17 00:00:00 2001 From: atanasster Date: Sun, 28 Mar 2021 11:38:17 -0400 Subject: [PATCH] fix: support for relatve paths in templates --- .vscode/launch.json | 2 +- plugins/addon-catalog/tests/stories.test.ts | 15 +++--- plugins/addon-images/tests/stories.test.ts | 15 +++--- plugins/addon-notes/tests/stories.test.ts | 15 +++--- plugins/addon-stats/tests/stories.test.ts | 15 +++--- plugins/axe-plugin/tests/stories.test.ts | 15 +++--- plugins/figma-embed/tests/stories.test.ts | 15 +++--- plugins/jest-snapshots/src/cli.ts | 1 + plugins/jest-snapshots/src/templates.ts | 12 +++-- .../jest-snapshots/templates/all-store.cjs.js | 1 + .../jest-snapshots/templates/all-store.esm.js | 1 + .../jest-snapshots/templates/all-store.ts.js | 1 + .../templates/store-loop/bundle.cjs.js | 2 +- .../templates/store-loop/bundle.esm.js | 2 +- .../templates/store-loop/bundle.ts.js | 2 +- .../templates/store-loop/imports.cjs.js | 2 +- .../templates/store-loop/imports.esm.js | 2 +- .../templates/store-loop/imports.ts.js | 2 +- .../enzyme-bundle-cjs.test.ts.snap | 5 +- .../enzyme-bundle-esm.test.ts.snap | 5 +- .../enzyme-bundle-ts.test.ts.snap | 5 +- .../__snapshots__/enzyme-cjs.test.ts.snap | 12 +++-- .../__snapshots__/enzyme-esm.test.ts.snap | 10 ++-- .../test/__snapshots__/enzyme-ts.test.ts.snap | 10 ++-- .../__snapshots__/rtl-bundle-cjs.test.ts.snap | 5 +- .../__snapshots__/rtl-bundle-esm.test.ts.snap | 5 +- .../__snapshots__/rtl-bundle-ts.test.ts.snap | 5 +- .../test/__snapshots__/rtl-cjs.test.ts.snap | 17 +++--- .../test/__snapshots__/rtl-esm.test.ts.snap | 17 +++--- .../test/__snapshots__/rtl-ts.test.ts.snap | 17 +++--- .../__snapshots__/rtr-bundle-cjs.test.ts.snap | 5 +- .../__snapshots__/rtr-bundle-esm.test.ts.snap | 5 +- .../__snapshots__/rtr-bundle-ts.test.ts.snap | 5 +- .../test/__snapshots__/rtr-cjs.test.ts.snap | 17 +++--- .../test/__snapshots__/rtr-esm.test.ts.snap | 17 +++--- .../test/__snapshots__/rtr-ts.test.ts.snap | 17 +++--- .../test/enzyme-bundle-cjs.test.ts | 14 ++--- .../test/enzyme-bundle-esm.test.ts | 14 ++--- .../test/enzyme-bundle-ts.test.ts | 13 ++--- .../jest-snapshots/test/enzyme-cjs.test.ts | 14 ++--- .../jest-snapshots/test/enzyme-esm.test.ts | 14 ++--- plugins/jest-snapshots/test/enzyme-ts.test.ts | 14 ++--- .../test/rtl-bundle-cjs.test.ts | 14 ++--- .../test/rtl-bundle-esm.test.ts | 14 ++--- .../jest-snapshots/test/rtl-bundle-ts.test.ts | 14 ++--- plugins/jest-snapshots/test/rtl-cjs.test.ts | 14 ++--- plugins/jest-snapshots/test/rtl-esm.test.ts | 14 ++--- plugins/jest-snapshots/test/rtl-ts.test.ts | 14 ++--- .../test/rtr-bundle-cjs.test.ts | 14 ++--- .../test/rtr-bundle-esm.test.ts | 14 ++--- .../jest-snapshots/test/rtr-bundle-ts.test.ts | 14 ++--- plugins/jest-snapshots/test/rtr-cjs.test.ts | 14 ++--- plugins/jest-snapshots/test/rtr-esm.test.ts | 14 ++--- plugins/jest-snapshots/test/rtr-ts.test.ts | 14 ++--- plugins/jest-snapshots/test/run-tests.ts | 53 +++++++++++-------- plugins/viewport-plugin/tests/stories.test.ts | 15 +++--- ui/app/tests/stories.test.ts | 15 +++--- ui/blocks/tests/stories.test.ts | 15 +++--- ui/components/tests/stories.test.ts | 15 +++--- ui/design-tokens/tests/stories.test.ts | 15 +++--- ui/editors/tests/stories.test.ts | 20 ++++--- 61 files changed, 320 insertions(+), 378 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index f9b47376e..babecb065 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -211,7 +211,7 @@ "name": "jest jest-addon", "program": "${workspaceFolder}/node_modules/.bin/jest", "cwd": "${workspaceFolder}/plugins/jest-snapshots", - "args": ["enzyme-esm"], + "args": ["enzyme-bundle-ts"], "console": "integratedTerminal", "internalConsoleOptions": "neverOpen", "disableOptimisticBPs": true, diff --git a/plugins/addon-catalog/tests/stories.test.ts b/plugins/addon-catalog/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/addon-catalog/tests/stories.test.ts +++ b/plugins/addon-catalog/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/addon-images/tests/stories.test.ts b/plugins/addon-images/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/addon-images/tests/stories.test.ts +++ b/plugins/addon-images/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/addon-notes/tests/stories.test.ts b/plugins/addon-notes/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/addon-notes/tests/stories.test.ts +++ b/plugins/addon-notes/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/addon-stats/tests/stories.test.ts b/plugins/addon-stats/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/addon-stats/tests/stories.test.ts +++ b/plugins/addon-stats/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/axe-plugin/tests/stories.test.ts b/plugins/axe-plugin/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/axe-plugin/tests/stories.test.ts +++ b/plugins/axe-plugin/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/figma-embed/tests/stories.test.ts b/plugins/figma-embed/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/figma-embed/tests/stories.test.ts +++ b/plugins/figma-embed/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/plugins/jest-snapshots/src/cli.ts b/plugins/jest-snapshots/src/cli.ts index ec8370731..40dc9938a 100644 --- a/plugins/jest-snapshots/src/cli.ts +++ b/plugins/jest-snapshots/src/cli.ts @@ -40,6 +40,7 @@ export const run = async (): Promise => { configPath: config, name, bundle, + out: testFolder, }); fs.writeFileSync(testFilePath, content, 'utf8'); }; diff --git a/plugins/jest-snapshots/src/templates.ts b/plugins/jest-snapshots/src/templates.ts index abd778ba8..fae9b3c64 100644 --- a/plugins/jest-snapshots/src/templates.ts +++ b/plugins/jest-snapshots/src/templates.ts @@ -12,14 +12,16 @@ export type TemplateOptions = { format?: TeplateFormats; configPath?: string; bundle?: string; + out?: string; name?: string; }; export const createTemplate = (options?: TemplateOptions): string => { const { renderer = 'rtl', format = 'cjs', - configPath = path.resolve(process.cwd(), defaultConfigFolder), + configPath: config = path.resolve(process.cwd(), defaultConfigFolder), name = 'component-controls generated', + out, bundle, } = options || {}; const filePath = path.resolve( @@ -52,17 +54,19 @@ export const createTemplate = (options?: TemplateOptions): string => { const render = dot.template(fs.readFileSync(renderPath, 'utf8'))({ storeRender, }); - + const bundlePath = + out && bundle ? `.${path.sep}${path.relative(out, bundle)}` : bundle; + const configPath = out ? path.relative(out, config) : config; const vars = { imports: fs.readFileSync(importsPath, 'utf8'), render, configPath, storeRender, storeImports: fs.readFileSync(storeImportPath, 'utf8'), - bundlePath: bundle, + bundlePath, storeLoop: dot.template(fs.readFileSync(storeLoopPath, 'utf8'))({ render, - bundlePath: bundle, + bundlePath, configPath, }), name, diff --git a/plugins/jest-snapshots/templates/all-store.cjs.js b/plugins/jest-snapshots/templates/all-store.cjs.js index 937daafb3..253030087 100644 --- a/plugins/jest-snapshots/templates/all-store.cjs.js +++ b/plugins/jest-snapshots/templates/all-store.cjs.js @@ -1,3 +1,4 @@ +const path = require('path'); {{=it.storeImports}} {{=it.imports}} diff --git a/plugins/jest-snapshots/templates/all-store.esm.js b/plugins/jest-snapshots/templates/all-store.esm.js index e89daad37..d7eea0e30 100644 --- a/plugins/jest-snapshots/templates/all-store.esm.js +++ b/plugins/jest-snapshots/templates/all-store.esm.js @@ -1,3 +1,4 @@ +import * as path from 'path'; {{=it.storeImports}} {{=it.imports}} diff --git a/plugins/jest-snapshots/templates/all-store.ts.js b/plugins/jest-snapshots/templates/all-store.ts.js index b739f4309..d76eb297a 100644 --- a/plugins/jest-snapshots/templates/all-store.ts.js +++ b/plugins/jest-snapshots/templates/all-store.ts.js @@ -1,3 +1,4 @@ +import path from 'path'; {{=it.storeImports}} {{=it.imports}} diff --git a/plugins/jest-snapshots/templates/store-loop/bundle.cjs.js b/plugins/jest-snapshots/templates/store-loop/bundle.cjs.js index 6a620097b..cc7012ef6 100644 --- a/plugins/jest-snapshots/templates/store-loop/bundle.cjs.js +++ b/plugins/jest-snapshots/templates/store-loop/bundle.cjs.js @@ -1,4 +1,4 @@ - const store = loadStore(require('{{=it.bundlePath}}')); + const store = loadStore(require(path.resolve(__dirname, '{{=it.bundlePath}}'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/templates/store-loop/bundle.esm.js b/plugins/jest-snapshots/templates/store-loop/bundle.esm.js index cdffa156e..d62b6247a 100644 --- a/plugins/jest-snapshots/templates/store-loop/bundle.esm.js +++ b/plugins/jest-snapshots/templates/store-loop/bundle.esm.js @@ -1,4 +1,4 @@ -const store = loadStore(require('{{=it.bundlePath}}')); +const store = loadStore(require(path.resolve(__dirname, '{{=it.bundlePath}}'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/templates/store-loop/bundle.ts.js b/plugins/jest-snapshots/templates/store-loop/bundle.ts.js index cdffa156e..d62b6247a 100644 --- a/plugins/jest-snapshots/templates/store-loop/bundle.ts.js +++ b/plugins/jest-snapshots/templates/store-loop/bundle.ts.js @@ -1,4 +1,4 @@ -const store = loadStore(require('{{=it.bundlePath}}')); +const store = loadStore(require(path.resolve(__dirname, '{{=it.bundlePath}}'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/templates/store-loop/imports.cjs.js b/plugins/jest-snapshots/templates/store-loop/imports.cjs.js index 9da0162c1..f042b2f19 100644 --- a/plugins/jest-snapshots/templates/store-loop/imports.cjs.js +++ b/plugins/jest-snapshots/templates/store-loop/imports.cjs.js @@ -1,4 +1,4 @@ - const configPath = '{{=it.configPath}}'; + const configPath = path.resolve(__dirname, '{{=it.configPath}}'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; diff --git a/plugins/jest-snapshots/templates/store-loop/imports.esm.js b/plugins/jest-snapshots/templates/store-loop/imports.esm.js index 9da0162c1..f042b2f19 100644 --- a/plugins/jest-snapshots/templates/store-loop/imports.esm.js +++ b/plugins/jest-snapshots/templates/store-loop/imports.esm.js @@ -1,4 +1,4 @@ - const configPath = '{{=it.configPath}}'; + const configPath = path.resolve(__dirname, '{{=it.configPath}}'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; diff --git a/plugins/jest-snapshots/templates/store-loop/imports.ts.js b/plugins/jest-snapshots/templates/store-loop/imports.ts.js index b70141cf9..ec308f8b1 100644 --- a/plugins/jest-snapshots/templates/store-loop/imports.ts.js +++ b/plugins/jest-snapshots/templates/store-loop/imports.ts.js @@ -1,4 +1,4 @@ - const configPath = '{{=it.configPath}}'; + const configPath = path.resolve(__dirname, '{{=it.configPath}}'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-cjs.test.ts.snap index 500f4e401..da682965d 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`enzyme bundle cjs 1`] = ` -"const { loadStore } = require('@component-controls/store'); +"const path = require('path'); +const { loadStore } = require('@component-controls/store'); const { render: reactRender } = require('@component-controls/render/react'); const { mount, configure } = require('enzyme'); @@ -35,7 +36,7 @@ describe('component-controls generated', () => { }); done(); }); - const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); + const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-esm.test.ts.snap index a6331f469..163f53aa9 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`enzyme bundle esm 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import * as path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import { mount, configure } from 'enzyme'; @@ -35,7 +36,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-ts.test.ts.snap index d03b04040..2802b9d46 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-bundle-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`enzyme bundle ts 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import { mount, configure } from 'enzyme'; @@ -35,7 +36,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-cjs.test.ts.snap index cba4f4401..cc20e2862 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`enzyme cjs 1`] = ` -"const { +exports[`enzyme cjs 1`] = ` +"const path = require('path'); +const { loadConfigurations, extractDocuments, } = require('@component-controls/config'); @@ -39,7 +40,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -57,11 +58,12 @@ describe('component-controls generated', () => { describe(doc.title, () => { examples.forEach(example => { it(example.name, async () => { - const rendered = renderExample({ + let rendered; + rendered = renderExample({ example, doc, config, - }); + }); const component = mount(rendered); const serialize = () => toJson(component, { mode: 'deep' }); diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-esm.test.ts.snap index a2fac205c..1279dbe25 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`enzyme esm 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`enzyme esm 1`] = ` +"import * as path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -36,7 +37,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -54,7 +55,8 @@ describe('component-controls generated', () => { describe(doc.title, () => { examples.forEach(example => { it(example.name, async () => { - const rendered = renderExample({ + let rendered; + rendered = renderExample({ example, doc, config, diff --git a/plugins/jest-snapshots/test/__snapshots__/enzyme-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/enzyme-ts.test.ts.snap index 7d3509d90..f9363fdfd 100644 --- a/plugins/jest-snapshots/test/__snapshots__/enzyme-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/enzyme-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`enzyme ts 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`enzyme ts 1`] = ` +"import path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -36,7 +37,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -54,7 +55,8 @@ describe('component-controls generated', () => { describe(doc.title, () => { examples.forEach(example => { it(example.name, async () => { - const rendered = renderExample({ + let rendered; + rendered = renderExample({ example, doc, config, diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-cjs.test.ts.snap index 8b0a0e58e..51da11f11 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtl bundle cjs 1`] = ` -"const { loadStore } = require('@component-controls/store'); +"const path = require('path'); +const { loadStore } = require('@component-controls/store'); const { render: reactRender } = require('@component-controls/render/react'); const { render, act } = require('@testing-library/react'); @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); - const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); + const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-esm.test.ts.snap index a25b6ec10..9aab45833 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtl bundle esm 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import * as path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import { render, act } from '@testing-library/react'; @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-ts.test.ts.snap index b9441a629..ee461d55c 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-bundle-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtl bundle ts 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import { render, act } from '@testing-library/react'; @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-cjs.test.ts.snap index 5536ba963..bb00b0cc5 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtl cjs 1`] = ` -"const { +exports[`rtl cjs 1`] = ` +"const path = require('path'); +const { loadConfigurations, extractDocuments, } = require('@component-controls/config'); @@ -35,7 +36,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -55,11 +56,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); const { asFragment: serialize } = render(rendered); diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-esm.test.ts.snap index 589187d25..c03e0fff0 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtl esm 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`rtl esm 1`] = ` +"import * as path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -32,7 +33,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -52,11 +53,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { diff --git a/plugins/jest-snapshots/test/__snapshots__/rtl-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtl-ts.test.ts.snap index dd43576d8..b9f24a08b 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtl-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtl-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtl ts 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`rtl ts 1`] = ` +"import path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -32,7 +33,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -52,11 +53,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-cjs.test.ts.snap index 49963d7cb..e453f2857 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtr bundle cjs 1`] = ` -"const { loadStore } = require('@component-controls/store'); +"const path = require('path'); +const { loadStore } = require('@component-controls/store'); const { render: reactRender } = require('@component-controls/render/react'); const renderer = require('react-test-renderer'); @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); - const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); + const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-esm.test.ts.snap index daf11d8f7..90c9b6181 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtr bundle esm 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import * as path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import renderer, { act } from 'react-test-renderer'; @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-ts.test.ts.snap index 7b951c574..364415428 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-bundle-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP exports[`rtr bundle ts 1`] = ` -"import { loadStore } from '@component-controls/store'; +"import path from 'path'; +import { loadStore } from '@component-controls/store'; const { render: reactRender } = require('@component-controls/render/react'); import renderer, { act } from 'react-test-renderer'; @@ -31,7 +32,7 @@ describe('component-controls generated', () => { }); done(); }); -const store = loadStore(require('/Users/atanasster/component-controls/plugins/jest-snapshots/test/bundle/component-controls.js')); +const store = loadStore(require(path.resolve(__dirname, './bundle/component-controls.js'))); const renderFn = store.config.renderFn || reactRender; Object.keys(store.docs).forEach(docId => { const doc = store.docs[docId]; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-cjs.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-cjs.test.ts.snap index 3778a4965..8b6d3285c 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-cjs.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-cjs.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtr cjs 1`] = ` -"const { +exports[`rtr cjs 1`] = ` +"const path = require('path'); +const { loadConfigurations, extractDocuments, } = require('@component-controls/config'); @@ -35,7 +36,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -55,12 +56,12 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; renderer.act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, }); + }) const component = renderer.create(rendered); const serialize = component ? component.toJSON : () => undefined; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-esm.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-esm.test.ts.snap index 2eff382a2..c13dc913d 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-esm.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-esm.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtr esm 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`rtr esm 1`] = ` +"import * as path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -32,7 +33,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -52,11 +53,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); const component = rendered ? renderer.create(rendered) : undefined; const serialize = component ? component.toJSON : () => undefined; diff --git a/plugins/jest-snapshots/test/__snapshots__/rtr-ts.test.ts.snap b/plugins/jest-snapshots/test/__snapshots__/rtr-ts.test.ts.snap index fa27b37da..e397496c9 100644 --- a/plugins/jest-snapshots/test/__snapshots__/rtr-ts.test.ts.snap +++ b/plugins/jest-snapshots/test/__snapshots__/rtr-ts.test.ts.snap @@ -1,7 +1,8 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`rtr ts 1`] = ` -"import { loadConfigurations, extractDocuments } from '@component-controls/config'; +exports[`rtr ts 1`] = ` +"import path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -32,7 +33,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = '/Users/atanasster/component-controls/plugins/jest-snapshots/test/.config'; + const configPath = path.resolve(__dirname, '.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -52,12 +53,12 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, }); + }) const component = rendered ? renderer.create(rendered) : undefined; const serialize = component ? component.toJSON : () => undefined; diff --git a/plugins/jest-snapshots/test/enzyme-bundle-cjs.test.ts b/plugins/jest-snapshots/test/enzyme-bundle-cjs.test.ts index f928f4065..2dd1f966a 100644 --- a/plugins/jest-snapshots/test/enzyme-bundle-cjs.test.ts +++ b/plugins/jest-snapshots/test/enzyme-bundle-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(1000000); -test('enzyme bundle cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'enzyme', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'enzyme', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/enzyme-bundle-esm.test.ts b/plugins/jest-snapshots/test/enzyme-bundle-esm.test.ts index 062497bdf..c77bbd448 100644 --- a/plugins/jest-snapshots/test/enzyme-bundle-esm.test.ts +++ b/plugins/jest-snapshots/test/enzyme-bundle-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('enzyme bundle esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'enzyme', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'enzyme', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/enzyme-bundle-ts.test.ts b/plugins/jest-snapshots/test/enzyme-bundle-ts.test.ts index c12168fd2..74908915b 100644 --- a/plugins/jest-snapshots/test/enzyme-bundle-ts.test.ts +++ b/plugins/jest-snapshots/test/enzyme-bundle-ts.test.ts @@ -1,14 +1,9 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; jest.setTimeout(100000); -test('enzyme bundle ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'enzyme', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'enzyme', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/enzyme-cjs.test.ts b/plugins/jest-snapshots/test/enzyme-cjs.test.ts index eaa20aa8c..9505f2295 100644 --- a/plugins/jest-snapshots/test/enzyme-cjs.test.ts +++ b/plugins/jest-snapshots/test/enzyme-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(1000000); -test('enzyme cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'enzyme', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'enzyme', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/enzyme-esm.test.ts b/plugins/jest-snapshots/test/enzyme-esm.test.ts index eb252ccff..8c1da9e87 100644 --- a/plugins/jest-snapshots/test/enzyme-esm.test.ts +++ b/plugins/jest-snapshots/test/enzyme-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('enzyme esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'enzyme', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'enzyme', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/enzyme-ts.test.ts b/plugins/jest-snapshots/test/enzyme-ts.test.ts index b2d44194e..e2369d03d 100644 --- a/plugins/jest-snapshots/test/enzyme-ts.test.ts +++ b/plugins/jest-snapshots/test/enzyme-ts.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('enzyme ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'enzyme', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'enzyme', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtl-bundle-cjs.test.ts b/plugins/jest-snapshots/test/rtl-bundle-cjs.test.ts index 82013200d..69fc16343 100644 --- a/plugins/jest-snapshots/test/rtl-bundle-cjs.test.ts +++ b/plugins/jest-snapshots/test/rtl-bundle-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl bundle cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'rtl', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'rtl', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtl-bundle-esm.test.ts b/plugins/jest-snapshots/test/rtl-bundle-esm.test.ts index fe4456497..5ad38bdbb 100644 --- a/plugins/jest-snapshots/test/rtl-bundle-esm.test.ts +++ b/plugins/jest-snapshots/test/rtl-bundle-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl bundle esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'rtl', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'rtl', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtl-bundle-ts.test.ts b/plugins/jest-snapshots/test/rtl-bundle-ts.test.ts index 39f07abcb..3ccf12f62 100644 --- a/plugins/jest-snapshots/test/rtl-bundle-ts.test.ts +++ b/plugins/jest-snapshots/test/rtl-bundle-ts.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl bundle ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'rtl', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'rtl', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtl-cjs.test.ts b/plugins/jest-snapshots/test/rtl-cjs.test.ts index 6540d471a..963d12d26 100644 --- a/plugins/jest-snapshots/test/rtl-cjs.test.ts +++ b/plugins/jest-snapshots/test/rtl-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'rtl', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'rtl', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtl-esm.test.ts b/plugins/jest-snapshots/test/rtl-esm.test.ts index 6f87791c3..4357d553b 100644 --- a/plugins/jest-snapshots/test/rtl-esm.test.ts +++ b/plugins/jest-snapshots/test/rtl-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'rtl', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'rtl', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtl-ts.test.ts b/plugins/jest-snapshots/test/rtl-ts.test.ts index 96ccb3c2a..190d55175 100644 --- a/plugins/jest-snapshots/test/rtl-ts.test.ts +++ b/plugins/jest-snapshots/test/rtl-ts.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtl ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'rtl', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'rtl', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtr-bundle-cjs.test.ts b/plugins/jest-snapshots/test/rtr-bundle-cjs.test.ts index afef5e08c..10909160d 100644 --- a/plugins/jest-snapshots/test/rtr-bundle-cjs.test.ts +++ b/plugins/jest-snapshots/test/rtr-bundle-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr bundle cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'rtr', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'rtr', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtr-bundle-esm.test.ts b/plugins/jest-snapshots/test/rtr-bundle-esm.test.ts index 2e799552d..f614d126c 100644 --- a/plugins/jest-snapshots/test/rtr-bundle-esm.test.ts +++ b/plugins/jest-snapshots/test/rtr-bundle-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr bundle esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'rtr', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'rtr', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtr-bundle-ts.test.ts b/plugins/jest-snapshots/test/rtr-bundle-ts.test.ts index 47fe04384..ec17f8cbb 100644 --- a/plugins/jest-snapshots/test/rtr-bundle-ts.test.ts +++ b/plugins/jest-snapshots/test/rtr-bundle-ts.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr bundle ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'rtr', - bundle: path.resolve(__dirname, 'bundle/component-controls.js'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'rtr', + bundle: path.resolve(__dirname, 'bundle/component-controls.js'), }); diff --git a/plugins/jest-snapshots/test/rtr-cjs.test.ts b/plugins/jest-snapshots/test/rtr-cjs.test.ts index 4dffd7ae5..1b3dd8b36 100644 --- a/plugins/jest-snapshots/test/rtr-cjs.test.ts +++ b/plugins/jest-snapshots/test/rtr-cjs.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr cjs', async () => { - const renderedFile = createTemplate({ - format: 'cjs', - renderer: 'rtr', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('cjs', renderedFile); +runTests({ + format: 'cjs', + renderer: 'rtr', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtr-esm.test.ts b/plugins/jest-snapshots/test/rtr-esm.test.ts index b6c50969f..2bef65189 100644 --- a/plugins/jest-snapshots/test/rtr-esm.test.ts +++ b/plugins/jest-snapshots/test/rtr-esm.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr esm', async () => { - const renderedFile = createTemplate({ - format: 'esm', - renderer: 'rtr', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('esm', renderedFile); +runTests({ + format: 'esm', + renderer: 'rtr', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/rtr-ts.test.ts b/plugins/jest-snapshots/test/rtr-ts.test.ts index e66a999a5..fde8b556e 100644 --- a/plugins/jest-snapshots/test/rtr-ts.test.ts +++ b/plugins/jest-snapshots/test/rtr-ts.test.ts @@ -1,14 +1,8 @@ import path from 'path'; -import { createTemplate } from '../src/templates'; import { runTests } from './run-tests'; -jest.setTimeout(100000); -test('rtr ts', async () => { - const renderedFile = createTemplate({ - format: 'ts', - renderer: 'rtr', - configPath: path.resolve(__dirname, '.config'), - }); - expect(renderedFile).toMatchSnapshot(); - await runTests('ts', renderedFile); +runTests({ + format: 'ts', + renderer: 'rtr', + configPath: path.resolve(__dirname, '.config'), }); diff --git a/plugins/jest-snapshots/test/run-tests.ts b/plugins/jest-snapshots/test/run-tests.ts index 0bd96df44..a75454661 100644 --- a/plugins/jest-snapshots/test/run-tests.ts +++ b/plugins/jest-snapshots/test/run-tests.ts @@ -2,29 +2,47 @@ import fs from 'fs'; import path from 'path'; import { runCLI } from 'jest'; import { Config } from '@jest/types'; -import { TeplateFormats } from '../src/types'; +import { createTemplate, TemplateOptions } from '../src/templates'; -export const runTests = async ( - format: TeplateFormats, - test: string, -): Promise => { +export const runTests = (props: TemplateOptions): void => { + const { renderer, format, configPath, bundle } = props; const extension = format === 'ts' ? 'ts' : 'js'; - const testFileName = path.resolve( - __dirname, - `test_example_run.test.${extension}`, - ); + const testName = `test_${renderer}_${format}${bundle ? '_bundle' : ''}`; + const testFileName = path.resolve(__dirname, `${testName}.test.${extension}`); const snapshotFileName = path.resolve( __dirname, - `__snapshots__/test_example_run.test.${extension}.snap`, + `__snapshots__/${testName}.test.${extension}.snap`, ); - try { - fs.writeFileSync(testFileName, test); + let renderedFile = ''; + beforeAll(() => { + renderedFile = createTemplate({ + format, + renderer, + bundle, + configPath, + out: __dirname, + }); + + fs.writeFileSync(testFileName, renderedFile); if (fs.existsSync(snapshotFileName)) { fs.unlinkSync(snapshotFileName); } + }); + + afterAll(() => { + if (fs.existsSync(testFileName)) { + fs.unlinkSync(testFileName); + } + if (fs.existsSync(snapshotFileName)) { + fs.unlinkSync(snapshotFileName); + } + }); + it(`${renderer} ${bundle ? 'bundle' : ''} ${format}`, async () => { + expect(renderedFile).toMatchSnapshot(); + await runCLI( { - testRegex: 'test_example_run', + testRegex: testName, testPathIgnorePatterns: ['/node_modules/', '/__snapshots__/'], silent: true, verbose: false, @@ -32,12 +50,5 @@ export const runTests = async ( } as Config.Argv, [__dirname], ); - } finally { - if (fs.existsSync(testFileName)) { - fs.unlinkSync(testFileName); - } - if (fs.existsSync(snapshotFileName)) { - fs.unlinkSync(snapshotFileName); - } - } + }, 1000000); }; diff --git a/plugins/viewport-plugin/tests/stories.test.ts b/plugins/viewport-plugin/tests/stories.test.ts index 43f8f5eb0..746dc188d 100644 --- a/plugins/viewport-plugin/tests/stories.test.ts +++ b/plugins/viewport-plugin/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('component-controls generated', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('component-controls generated', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('component-controls generated', () => { }); } }); - } + } }); diff --git a/ui/app/tests/stories.test.ts b/ui/app/tests/stories.test.ts index 4a0253393..a3aec89e8 100644 --- a/ui/app/tests/stories.test.ts +++ b/ui/app/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('app', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('app', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('app', () => { }); } }); - } + } }); diff --git a/ui/blocks/tests/stories.test.ts b/ui/blocks/tests/stories.test.ts index ba44509c6..9e3ca2202 100644 --- a/ui/blocks/tests/stories.test.ts +++ b/ui/blocks/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('blocks', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('blocks', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('blocks', () => { }); } }); - } + } }); diff --git a/ui/components/tests/stories.test.ts b/ui/components/tests/stories.test.ts index cef00d53f..70db14fd3 100644 --- a/ui/components/tests/stories.test.ts +++ b/ui/components/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('components', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('components', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('components', () => { }); } }); - } + } }); diff --git a/ui/design-tokens/tests/stories.test.ts b/ui/design-tokens/tests/stories.test.ts index 47e72b98f..90b420a38 100644 --- a/ui/design-tokens/tests/stories.test.ts +++ b/ui/design-tokens/tests/stories.test.ts @@ -1,3 +1,4 @@ +import path from 'path'; import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -29,7 +30,7 @@ describe('design-tokens', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -49,11 +50,11 @@ describe('design-tokens', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -68,5 +69,5 @@ describe('design-tokens', () => { }); } }); - } + } }); diff --git a/ui/editors/tests/stories.test.ts b/ui/editors/tests/stories.test.ts index 4d36d3787..085581ba0 100644 --- a/ui/editors/tests/stories.test.ts +++ b/ui/editors/tests/stories.test.ts @@ -1,7 +1,5 @@ -import { - loadConfigurations, - extractDocuments, -} from '@component-controls/config'; +import path from 'path'; +import { loadConfigurations, extractDocuments } from '@component-controls/config'; import { renderExample } from '@component-controls/test-renderers'; import { render as reactRender } from '@component-controls/render/react'; @@ -32,7 +30,7 @@ describe('editors', () => { }); done(); }); - const configPath = './.config'; + const configPath = path.resolve(__dirname, '../.config'); const config = loadConfigurations(configPath); if (!config.renderFn) { config.renderFn = reactRender; @@ -52,11 +50,11 @@ describe('editors', () => { it(example.name, async () => { let rendered; act(() => { - rendered = renderExample({ - example, - doc, - config, - }); + rendered = renderExample({ + example, + doc, + config, + }); }); let serialize; if (rendered) { @@ -71,5 +69,5 @@ describe('editors', () => { }); } }); - } + } });