diff --git a/packages/adapter-next/test/plugin-project-init.test.ts b/packages/adapter-next/test/plugin-project-init.test.ts index bb7b9b99b0..6e8d332ac5 100644 --- a/packages/adapter-next/test/plugin-project-init.test.ts +++ b/packages/adapter-next/test/plugin-project-init.test.ts @@ -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} * @@ -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, { @@ -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} * @@ -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, { @@ -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} */ @@ -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} */ @@ -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} * @@ -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, { @@ -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} * @@ -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, { @@ -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} */ @@ -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} */ @@ -1385,7 +1389,7 @@ describe("/api/preview route", () => { export default async function handler( req: NextApiRequest, - res: NextApiResponse + res: NextApiResponse, ) { const client = createClient({ req }); diff --git a/packages/adapter-next/test/plugin-snippet-read.test.ts b/packages/adapter-next/test/plugin-snippet-read.test.ts index 79cd4427b3..b61af13b53 100644 --- a/packages/adapter-next/test/plugin-snippet-read.test.ts +++ b/packages/adapter-next/test/plugin-snippet-read.test.ts @@ -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(/;$/, ""), }); diff --git a/packages/adapter-nuxt/package.json b/packages/adapter-nuxt/package.json index 3f5d926c4c..971faf9b28 100644 --- a/packages/adapter-nuxt/package.json +++ b/packages/adapter-nuxt/package.json @@ -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", diff --git a/packages/adapter-nuxt/test/plugin-snippet-read.test.ts b/packages/adapter-nuxt/test/plugin-snippet-read.test.ts index 4c0a3e04e0..c8a4bcd61d 100644 --- a/packages/adapter-nuxt/test/plugin-snippet-read.test.ts +++ b/packages/adapter-nuxt/test/plugin-snippet-read.test.ts @@ -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(/;$/, ""), }); diff --git a/packages/adapter-nuxt2/package.json b/packages/adapter-nuxt2/package.json index e9eecdd4ac..02e10bf121 100644 --- a/packages/adapter-nuxt2/package.json +++ b/packages/adapter-nuxt2/package.json @@ -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", diff --git a/packages/adapter-nuxt2/test/plugin-snippet-read.test.ts b/packages/adapter-nuxt2/test/plugin-snippet-read.test.ts index 4c0a3e04e0..c8a4bcd61d 100644 --- a/packages/adapter-nuxt2/test/plugin-snippet-read.test.ts +++ b/packages/adapter-nuxt2/test/plugin-snippet-read.test.ts @@ -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(/;$/, ""), }); diff --git a/packages/adapter-sveltekit/test/plugin-project-init.test.ts b/packages/adapter-sveltekit/test/plugin-project-init.test.ts index 19975376d1..752a35852e 100644 --- a/packages/adapter-sveltekit/test/plugin-project-init.test.ts +++ b/packages/adapter-sveltekit/test/plugin-project-init.test.ts @@ -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} * @@ -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} */ diff --git a/packages/adapter-sveltekit/test/plugin-snippet-read.test.ts b/packages/adapter-sveltekit/test/plugin-snippet-read.test.ts index febdb9528e..6504347c77 100644 --- a/packages/adapter-sveltekit/test/plugin-snippet-read.test.ts +++ b/packages/adapter-sveltekit/test/plugin-snippet-read.test.ts @@ -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(/;$/, ""), }); diff --git a/packages/manager/test/__setup__.ts b/packages/manager/test/__setup__.ts index 2dbfa94492..75040b5b5c 100644 --- a/packages/manager/test/__setup__.ts +++ b/packages/manager/test/__setup__.ts @@ -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) => { @@ -119,7 +123,7 @@ vi.mock("module", async () => { return `${MOCK_BASE_DIRECTORY}/${id}`; } - return actualCreateRequire(id); + return actualCreateRequire.resolve(id); }, }; }, diff --git a/packages/slice-machine/test/__setup__.ts b/packages/slice-machine/test/__setup__.ts index 27c6c95960..7fcdfac3e6 100644 --- a/packages/slice-machine/test/__setup__.ts +++ b/packages/slice-machine/test/__setup__.ts @@ -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(); diff --git a/yarn.lock b/yarn.lock index 58485a23e8..6c6e336883 100644 --- a/yarn.lock +++ b/yarn.lock @@ -8140,7 +8140,6 @@ __metadata: "@prismicio/types-internal": ^2.2.0 "@size-limit/preset-small-lib": 8.2.4 "@slicemachine/plugin-kit": "workspace:^" - "@types/prettier": 3.0.0 "@typescript-eslint/eslint-plugin": 5.55.0 "@typescript-eslint/parser": 5.55.0 "@vitest/coverage-v8": 0.32.0 @@ -8184,7 +8183,6 @@ __metadata: "@size-limit/preset-small-lib": 8.2.4 "@slicemachine/plugin-kit": "workspace:^" "@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 @@ -10552,15 +10550,6 @@ __metadata: languageName: node linkType: hard -"@types/prettier@npm:3.0.0": - version: 3.0.0 - resolution: "@types/prettier@npm:3.0.0" - dependencies: - prettier: "*" - checksum: a2a512d304e5bcf78f38089dc88ad19215e6ab871d435a17aef3ce538a63b07c0e359c18db23989dc1ed9fff96d99eee1f680416080184df5c7e0e3bf767e165 - languageName: node - linkType: hard - "@types/pretty-hrtime@npm:^1.0.0": version: 1.0.1 resolution: "@types/pretty-hrtime@npm:1.0.1" @@ -28153,7 +28142,7 @@ __metadata: languageName: node linkType: hard -"prettier@npm:*, prettier@npm:3.0.3, prettier@npm:^3.0.3": +"prettier@npm:3.0.3, prettier@npm:^3.0.3": version: 3.0.3 resolution: "prettier@npm:3.0.3" bin: