Skip to content

Commit

Permalink
test(deps): update test to run with prettier 3
Browse files Browse the repository at this point in the history
  • Loading branch information
lihbr committed Oct 20, 2023
1 parent ecead99 commit e9ba134
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 90 deletions.
70 changes: 37 additions & 33 deletions packages/adapter-next/test/plugin-project-init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,12 +254,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*
Expand All @@ -282,8 +283,7 @@ describe("prismicio.js file", () => {
* Creates a Prismic client for the project's repository. The client is used to
* query content from the Prismic API.
*
* @param {prismicNext.CreateClientConfig} config - Configuration for the
* Prismic client.
* @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
*/
export const createClient = (config = {}) => {
const client = prismic.createClient(repositoryName, {
Expand Down Expand Up @@ -328,12 +328,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"../slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*
Expand All @@ -356,8 +357,7 @@ describe("prismicio.js file", () => {
* Creates a Prismic client for the project's repository. The client is used to
* query content from the Prismic API.
*
* @param {prismicNext.CreateClientConfig} config - Configuration for the
* Prismic client.
* @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
*/
export const createClient = (config = {}) => {
const client = prismic.createClient(repositoryName, {
Expand Down Expand Up @@ -402,12 +402,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*/
Expand Down Expand Up @@ -476,12 +477,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*/
Expand Down Expand Up @@ -547,12 +549,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*
Expand All @@ -575,8 +578,7 @@ describe("prismicio.js file", () => {
* Creates a Prismic client for the project's repository. The client is used to
* query content from the Prismic API.
*
* @param {prismicNext.CreateClientConfig} config - Configuration for the
* Prismic client.
* @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
*/
export const createClient = (config = {}) => {
const client = prismic.createClient(repositoryName, {
Expand Down Expand Up @@ -617,12 +619,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"../slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*
Expand All @@ -645,8 +648,7 @@ describe("prismicio.js file", () => {
* Creates a Prismic client for the project's repository. The client is used to
* query content from the Prismic API.
*
* @param {prismicNext.CreateClientConfig} config - Configuration for the
* Prismic client.
* @param {prismicNext.CreateClientConfig} config - Configuration for the Prismic client.
*/
export const createClient = (config = {}) => {
const client = prismic.createClient(repositoryName, {
Expand Down Expand Up @@ -691,12 +693,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*/
Expand Down Expand Up @@ -761,12 +764,13 @@ describe("prismicio.js file", () => {
import * as prismicNext from \\"@prismicio/next\\";
import config from \\"./slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*/
Expand Down Expand Up @@ -1385,7 +1389,7 @@ describe("/api/preview route", () => {
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
res: NextApiResponse,
) {
const client = createClient({ req });
Expand Down
20 changes: 11 additions & 9 deletions packages/adapter-next/test/plugin-snippet-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,22 @@ const testSnippet = (

if (Array.isArray(expected)) {
expect(res).toStrictEqual(
expected.map((descriptor) => ({
...descriptor,
code: prettier
.format(descriptor.code, { parser: "typescript" })
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
await Promise.all(
expected.map(async (descriptor) => ({
...descriptor,
code: (
await prettier.format(descriptor.code, { parser: "typescript" })
)
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
),
);
} else {
expect(res).toStrictEqual({
label: "React",
language: "tsx",
code: prettier
.format(expected, { parser: "typescript" })
code: (await prettier.format(expected, { parser: "typescript" }))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
});
Expand Down
1 change: 0 additions & 1 deletion packages/adapter-nuxt/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
"@prismicio/mock": "0.2.0",
"@size-limit/preset-small-lib": "8.2.4",
"@types/common-tags": "1.8.1",
"@types/prettier": "3.0.0",
"@typescript-eslint/eslint-plugin": "5.55.0",
"@typescript-eslint/parser": "5.55.0",
"@vitest/coverage-v8": "0.32.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/adapter-nuxt/test/plugin-snippet-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ const testSnippet = (

if (Array.isArray(expected)) {
expect(res).toStrictEqual(
expected.map((descriptor) => ({
...descriptor,
code: prettier
.format(descriptor.code, { parser: "vue" })
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
await Promise.all(
expected.map(async (descriptor) => ({
...descriptor,
code: (await prettier.format(descriptor.code, { parser: "vue" }))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
),
);
} else {
expect(res).toStrictEqual({
label: "Vue",
language: "vue",
code: prettier
.format(expected, { parser: "vue" })
code: (await prettier.format(expected, { parser: "vue" }))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
});
Expand Down
1 change: 0 additions & 1 deletion packages/adapter-nuxt2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@
"devDependencies": {
"@prismicio/mock": "0.2.0",
"@size-limit/preset-small-lib": "8.2.4",
"@types/prettier": "3.0.0",
"@typescript-eslint/eslint-plugin": "5.55.0",
"@typescript-eslint/parser": "5.55.0",
"@vitest/coverage-v8": "0.32.0",
Expand Down
18 changes: 9 additions & 9 deletions packages/adapter-nuxt2/test/plugin-snippet-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,20 +50,20 @@ const testSnippet = (

if (Array.isArray(expected)) {
expect(res).toStrictEqual(
expected.map((descriptor) => ({
...descriptor,
code: prettier
.format(descriptor.code, { parser: "vue" })
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
await Promise.all(
expected.map(async (descriptor) => ({
...descriptor,
code: (await prettier.format(descriptor.code, { parser: "vue" }))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
),
);
} else {
expect(res).toStrictEqual({
label: "Vue",
language: "vue",
code: prettier
.format(expected, { parser: "vue" })
code: (await prettier.format(expected, { parser: "vue" }))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
});
Expand Down
14 changes: 8 additions & 6 deletions packages/adapter-sveltekit/test/plugin-project-init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,12 +260,13 @@ describe("prismicio.js file", () => {
"import * as prismic from \\"@prismicio/client\\";
import config from \\"../../slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*
Expand Down Expand Up @@ -325,12 +326,13 @@ describe("prismicio.js file", () => {
"import * as prismic from \\"@prismicio/client\\";
import config from \\"../../slicemachine.config.json\\";
/** The project's Prismic repository name. */
/**
* The project's Prismic repository name.
*/
export const repositoryName = config.repositoryName;
/**
* A list of Route Resolver objects that define how a document's \`url\` field is
* resolved.
* A list of Route Resolver objects that define how a document's \`url\` field is resolved.
*
* {@link https://prismic.io/docs/route-resolver#route-resolver}
*/
Expand Down
18 changes: 9 additions & 9 deletions packages/adapter-sveltekit/test/plugin-snippet-read.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,20 @@ const testSnippet = (

if (Array.isArray(expected)) {
expect(res).toStrictEqual(
expected.map((descriptor) => ({
...descriptor,
code: prettier
.format(descriptor.code, prettierConfig)
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
await Promise.all(
expected.map(async (descriptor) => ({
...descriptor,
code: (await prettier.format(descriptor.code, prettierConfig))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
})),
),
);
} else {
expect(res).toStrictEqual({
label: "Svelte",
language: "svelte",
code: prettier
.format(expected, prettierConfig)
code: (await prettier.format(expected, prettierConfig))
.replace(/[\r\n]+$/, "")
.replace(/;$/, ""),
});
Expand Down
6 changes: 5 additions & 1 deletion packages/manager/test/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ vi.mock("module", async () => {
createRequire: (...args) => {
const actualCreateRequire = actual.createRequire(...args);

if (args[0].toString().includes("prettier")) {
return actualCreateRequire;
}

return {
...actualCreateRequire,
resolve: (id: string) => {
Expand All @@ -119,7 +123,7 @@ vi.mock("module", async () => {
return `${MOCK_BASE_DIRECTORY}/${id}`;
}

return actualCreateRequire(id);
return actualCreateRequire.resolve(id);
},
};
},
Expand Down
13 changes: 13 additions & 0 deletions packages/slice-machine/test/__setup__.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,19 @@ vi.mock("fs/promises", async () => {
};
});

// jsdom environment removes Node native modules which is desired.
// However, because we create a plugin before each tests and that
// they rely on Prettier, which relies on `node:url`, we need to
// bypass jsdom restricted browser environment by mocking `node:url`
// to itself.
vi.mock("url", async () => {
const actual: typeof import("node:url") = (await vi.importActual(
"node:url",
));

return actual;
});

vi.mock("analytics-node", () => {
const MockSegmentClient = vi.fn();

Expand Down
Loading

0 comments on commit e9ba134

Please sign in to comment.