From 728f73f8fa7b2ed4c841550a08909511d8116ec2 Mon Sep 17 00:00:00 2001 From: Michael Rawlings Date: Tue, 26 Nov 2019 13:35:53 -0800 Subject: [PATCH] fix: don't load .marko.js as fixture, add docs for .js fixture --- README.md | 19 +++++++++++-------- src/index.ts | 13 ++++++++----- 2 files changed, 19 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 2a1945b..accec2a 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,9 @@ src/ components/ app-carousel/ fixtures/ - data.json # data to render app-carousel/index.marko with - template.marko # a template assumed to use + fixture1.js # exports data to render app-carousel/index.marko with + fixture2.json # data to render app-carousel/index.marko with + fixture3.marko # a template assumed to use index.marko ``` @@ -62,10 +63,12 @@ Loads all the fixtures under `path` and generates tests that render them and com ```bash fixtures/ - data.json - data.html # snapshot of app-carousel/index.marko rendered with data.json - template.marko - template.html # snapshot of a template.marko + fixture1.js + fixture1.html # snapshot of app-carousel/index.marko rendered with data from fixture1.js + fixture2.json + fixture2.html # snapshot of app-carousel/index.marko rendered with data from fixture2.json + fixture3.marko + fixture3.html # snapshot of fixture3.marko ``` ```typescript @@ -96,7 +99,7 @@ describe("fixture snapshots", () => { #### Usage with Mocha ```javascript -import runSnapshotTests from "@marko/fixture-snapshots/mocha"; +import runSnapshotTests from "@marko/fixture-snapshots/mocha"; // const runSnapshotTests = require("@marko/fixture-snapshots/mocha").default; describe("fixture snapshots", () => { @@ -135,7 +138,7 @@ type ComponentFixtures = { { name: string; path: string; // the absolute path to the fixture - ext: ".json" | ".marko"; + ext: ".js" | ".json" | ".marko"; fixture: object | Template; // the loaded fixture render: () => RenderResult; // render the fixture, return type is the same as `@marko/testing-library`'s render function toString: (normalizer = defaultNormalizer) => Promise; diff --git a/src/index.ts b/src/index.ts index 2c10382..15190c7 100644 --- a/src/index.ts +++ b/src/index.ts @@ -31,7 +31,7 @@ export function findComponentFixtures( const componentName = inferName(componentPath); const fixturesPath = path.join(path.dirname(componentPath), fixtureDir); const fixtures = glob - .sync("*.{json,marko,js}", { cwd: fixturesPath }) + .sync("!(*.marko.).{json,marko,js}", { cwd: fixturesPath }) .map((fixtureRelativePath: string) => { const fixturePath = path.join(fixturesPath, fixtureRelativePath); const fixtureExtension = path.extname(fixturePath); @@ -56,10 +56,13 @@ export function findComponentFixtures( render: renderFn }; }) - .reduce((lookup, current) => { - lookup[current.name] = current; - return lookup; - }, {} as ComponentFixtures["fixtures"]); + .reduce( + (lookup, current) => { + lookup[current.name] = current; + return lookup; + }, + {} as ComponentFixtures["fixtures"] + ); if (Object.keys(fixtures).length) { return { get component() {