Skip to content

Commit 64e960c

Browse files
committed
fix: tests
1 parent a241343 commit 64e960c

2 files changed

Lines changed: 19 additions & 35 deletions

File tree

packages/cli/src/cli/loaders/mdx2/code-placeholder.spec.ts

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import dedent from "dedent";
44
import { md5 } from "../../utils/md5";
55

66
const sampleMdxContent = dedent`
7-
Paragraph with some \`inline\` code.
7+
Paragraph with some code:
88
99
\`\`\`js
1010
console.log("foo");
@@ -16,53 +16,36 @@ describe("mdx code placeholder loader", () => {
1616
const loader = createMdxCodePlaceholderLoader();
1717
loader.setDefaultLocale("en");
1818

19-
const result = await loader.pull("en", {
20-
frontmatter: {},
21-
content: sampleMdxContent,
22-
});
19+
const result = await loader.pull("en", sampleMdxContent);
2320
// expect two placeholders
24-
const placeholderKeys = Object.keys(result.codePlaceholders);
25-
const placeholder1 = `__PLACEHOLDER_${md5("`inline`")}__`;
26-
const placeholder2 = `__PLACEHOLDER_${md5('```js\nconsole.log("foo");\n```')}__`;
27-
expect(placeholderKeys).toEqual([placeholder1, placeholder2]);
21+
const placeholder = `---CODE_PLACEHOLDER_${md5('```js\nconsole.log("foo");\n```')}---`;
2822

29-
// mapping values should equal original code snippets
30-
const expectedInline = "`inline`";
31-
const expectedBlock = '```js\nconsole.log("foo");\n```';
32-
expect(Object.values(result.codePlaceholders).sort()).toEqual(
33-
[expectedBlock, expectedInline].sort(),
34-
);
23+
expect(result).toEqual(
24+
dedent`
25+
Paragraph with some code:
3526
36-
// content should have placeholders substituted exactly
37-
const expectedContent = `Paragraph with some ${placeholder1} code.\n\n${placeholder2}`;
38-
expect(result.content.trim()).toBe(expectedContent.trim());
27+
${placeholder}
28+
`,
29+
);
3930
});
4031

4132
it("should restore original code segments on push", async () => {
4233
const loader = createMdxCodePlaceholderLoader();
4334
loader.setDefaultLocale("en");
4435

45-
const pulled = await loader.pull("en", {
46-
frontmatter: {},
47-
content: sampleMdxContent,
48-
});
36+
const pulled = await loader.pull("en", sampleMdxContent);
37+
const modified = pulled.replace("Paragraph", "Párrafo");
4938

50-
// modify pulled data
51-
pulled.content = pulled.content.replace("Paragraph", "Párrafo");
39+
const output = await loader.push("es", modified);
5240

53-
const output = await loader.push("es", pulled);
54-
55-
const expectedOutput = {
56-
frontmatter: {},
57-
content: dedent`
58-
Párrafo with some \`inline\` code.
41+
expect(output).toEqual(
42+
dedent`
43+
Párrafo with some code:
5944
6045
\`\`\`js
6146
console.log("foo");
6247
\`\`\`
6348
`,
64-
};
65-
66-
expect(output).toEqual(expectedOutput);
49+
);
6750
});
6851
});

packages/cli/src/cli/loaders/prettier.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ export type PrettierLoaderOptions = {
1313
export default function createPrettierLoader(
1414
options: PrettierLoaderOptions,
1515
): ILoader<string, string> {
16+
const stage = options.stage || "both";
1617
return createLoader({
1718
async pull(locale, data) {
18-
if (!["pull", "both"].includes(options.stage!)) {
19+
if (!["pull", "both"].includes(stage)) {
1920
return data;
2021
}
2122

@@ -28,7 +29,7 @@ export default function createPrettierLoader(
2829
return await formatDataWithPrettier(data, finalPath, options);
2930
},
3031
async push(locale, data) {
31-
if (!["push", "both"].includes(options.stage!)) {
32+
if (!["push", "both"].includes(stage)) {
3233
return data;
3334
}
3435

0 commit comments

Comments
 (0)