Skip to content

Commit

Permalink
Merge pull request #26 from PrashantAshok/arc-support
Browse files Browse the repository at this point in the history
feat: add arc support
  • Loading branch information
DylanPiercey authored Jun 5, 2023
2 parents e6b10e1 + 0b9069e commit 9c707dd
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 4 deletions.
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion src/jest.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { cleanup } from "@marko/testing-library";
import { findProjectFixtures, defaultNormalizer } from "./";
import { toMatchFile } from "jest-file-snapshot";
import { getArcFlag } from "./utils";

expect.extend({ toMatchFile });

Expand All @@ -15,8 +16,10 @@ export default function snapshotComponentFixtures(
Object.keys(component.fixtures).forEach(name => {
it(name, async () => {
const fixture = component.fixtures[name];
const arcFlag = getArcFlag(component.path); // this returns "[mobile]"

expect(await fixture.toString(normalize)).toMatchFile(
fixture.path.replace(fixture.ext, ".html")
fixture.path.replace(fixture.ext, `${arcFlag}.html`)
);
});
});
Expand Down
5 changes: 4 additions & 1 deletion src/mocha.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import path from "path";
import assert from "assert";
import { cleanup } from "@marko/testing-library";
import { findProjectFixtures, defaultNormalizer } from "./";
import { getArcFlag } from "./utils";

declare const before: (fn: () => any) => any;

Expand All @@ -17,8 +18,10 @@ export default function snapshotComponentFixtures(
Object.keys(component.fixtures).forEach(name => {
it(name, async () => {
const fixture = component.fixtures[name];
const arcFlag = getArcFlag(component.path); // this returns "[mobile]"

snapshot(
fixture.path.replace(fixture.ext, ".html"),
fixture.path.replace(fixture.ext, `${arcFlag}.html`),
await fixture.toString(normalize)
);
});
Expand Down
21 changes: 21 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import path from "path";

export function getArcFlag(filename: string) {
const start = filename.lastIndexOf(path.sep) + 1;
const leftDot = filename.indexOf(".", start);

const closeBracket = leftDot - 1;
if (filename[closeBracket] === "]") {
const openBracket = filename.lastIndexOf("[", closeBracket);
if (openBracket > start) {
// If we match a "]" before the extension and find a "[" before that,
// then we have an arc flag. Strip it off.
return (
filename.slice(openBracket, closeBracket + 1)
);
}
}

return '';
}

3 changes: 3 additions & 0 deletions test/components/hello/fixtures/data[mobile].html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Hello Arc File Data!
</div>
3 changes: 3 additions & 0 deletions test/components/hello/fixtures/template[mobile].html
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
Hello Template!
</div>
2 changes: 2 additions & 0 deletions test/components/hello/index[mobile].marko
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
class {}
<div>Hello Arc File ${input.name}!</div>
26 changes: 26 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,32 @@ describe("findProjectFixtures", () => {
"name": "hello",
"path": "(cwd)/test/components/hello/index.marko",
},
Object {
"component": [Component "(cwd)/test/components/hello/index[mobile].marko"],
"fixtures": Object {
"data": Object {
"ext": ".json",
"fixture": Object {
"name": "Data",
},
"name": "data",
"path": "(cwd)/test/components/hello/fixtures/data.json",
"render": [Function],
"toString": [Function],
},
"template": Object {
"ext": ".marko",
"fixture": [Component "(cwd)/test/components/hello/fixtures/template.marko"],
"name": "template",
"path": "(cwd)/test/components/hello/fixtures/template.marko",
"render": [Function],
"toString": [Function],
},
},
"fixturesPath": "(cwd)/test/components/hello/fixtures",
"name": "hello",
"path": "(cwd)/test/components/hello/index[mobile].marko",
},
]
`);
});
Expand Down

0 comments on commit 9c707dd

Please sign in to comment.