Skip to content

Commit

Permalink
fix: don't load .marko.js as fixture, add docs for .js fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
mlrawlings committed Nov 26, 2019
1 parent 4341bf5 commit 728f73f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
19 changes: 11 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <app-carousel>
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 <app-carousel>
index.marko
```

Expand All @@ -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
Expand Down Expand Up @@ -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", () => {
Expand Down Expand Up @@ -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<string>;
Expand Down
13 changes: 8 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() {
Expand Down

0 comments on commit 728f73f

Please sign in to comment.