jest.mock( "rollup-plugin-dev", () => jest.fn((config: any) => ({ name: "dev", ...config })), { virtual: true }, ); const mockLivereloadServer = { watch: jest.fn(), close: jest.fn(), once: jest.fn(), server: { once: jest.fn((event: string, cb: () => void) => cb()) }, }; jest.mock( "livereload", () => ({ createServer: jest.fn(() => mockLivereloadServer) }), { virtual: true }, ); import fs from "fs"; import path from "path"; import type { Plugin, PluginContext } from "rollup"; import { servicenowFrontEndPlugins, createUpdateSrcPath, } from "../../dist/index.js"; const makeCredential = (url = "https://dev12345.service-now.com/") => ({ getUrl: () => new URL(url), getHeaders: async () => ({ Authorization: "Bearer token123" }), }); describe("ServiceNow Front-End Plugins", () => { beforeEach(() => { jest.clearAllMocks(); jest.spyOn(console, "warn").mockImplementation(() => {}); }); afterEach(() => { jest.restoreAllMocks(); }); describe("outputOptions configuration", () => { const findOutputOptionsPlugin = (plugins: Plugin | Plugin[]) => { const pluginArray = Array.isArray(plugins) ? plugins : [plugins]; return pluginArray.find((p) => p && p.name === "output-options"); }; test("should configure entryFileNames and chunkFileNames without hash (to avoid creating delete records)", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const outputOptionsPlugin = findOutputOptionsPlugin(plugins as Plugin[]); expect(outputOptionsPlugin).toBeDefined(); if ( !outputOptionsPlugin || typeof outputOptionsPlugin.outputOptions !== "function" ) { throw new Error("outputOptions plugin not found or invalid"); } const rawOptions = { dir: "dist", format: "es" as const, }; const result = await outputOptionsPlugin.outputOptions.call( {} as PluginContext, rawOptions, ); expect(result).toEqual({ dir: "dist", format: "es", entryFileNames: "[name].jsdbx", chunkFileNames: "[name].jsdbx", }); }); test("should configure chunkFileNames without content hash", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const outputOptionsPlugin = findOutputOptionsPlugin(plugins as Plugin[]); if ( !outputOptionsPlugin || typeof outputOptionsPlugin.outputOptions !== "function" ) { throw new Error("outputOptions plugin not found or invalid"); } const rawOptions = { file: "dist/bundle.js", }; const result = await outputOptionsPlugin.outputOptions.call( {} as PluginContext, rawOptions, ); expect(result?.chunkFileNames).toBe("[name].jsdbx"); }); test("should handle array of output options", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const outputOptionsPlugin = findOutputOptionsPlugin(plugins as Plugin[]); if ( !outputOptionsPlugin || typeof outputOptionsPlugin.outputOptions !== "function" ) { throw new Error("outputOptions plugin not found or invalid"); } const rawOptions: any = [ { dir: "dist/esm", format: "es" as const }, { dir: "dist/cjs", format: "cjs" as const }, ]; const result = await outputOptionsPlugin.outputOptions.call( {} as PluginContext, rawOptions, ); expect(Array.isArray(result)).toBe(true); if (Array.isArray(result)) { expect(result[0].entryFileNames).toBe("[name].jsdbx"); expect(result[0].chunkFileNames).toBe("[name].jsdbx"); expect(result[1].entryFileNames).toBe("[name].jsdbx"); expect(result[1].chunkFileNames).toBe("[name].jsdbx"); } }); test("should not modify output options when preserveSrc is true", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", dev: true, // Sets preserveSrc to true }); const outputOptionsPlugin = findOutputOptionsPlugin(plugins as Plugin[]); expect(outputOptionsPlugin).toBeUndefined(); }); }); describe("cache busting configuration", () => { /** * Helper to create updateSrcPath function with test configuration */ const createUpdateSrcPathTest = (config: { enableCacheBusting?: boolean; preserveSrc?: boolean; }) => { return createUpdateSrcPath({ scope: "x_test_app", preserveSrc: config.preserveSrc ?? false, enableCacheBusting: config.enableCacheBusting ?? true, }); }; test("should add cache busting parameter when enableCacheBusting is true", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: true, }); const result = updateSrcPath("./script.js", "script"); // Should include the cache busting parameter expect(result).toContain("/uxasset/externals/x_test_app/script.jsdbx?"); expect(result).toContain( "uxpcb=$[UxFrameworkScriptables.getFlushTimestamp()]", ); }); test("should add cache busting parameter when enableCacheBusting is not specified (default is true)", () => { const updateSrcPath = createUpdateSrcPathTest({}); // Default is true const result = updateSrcPath("./script.js", "script"); // Should include the cache busting parameter expect(result).toContain("/uxasset/externals/x_test_app/script.jsdbx?"); expect(result).toContain( "uxpcb=$[UxFrameworkScriptables.getFlushTimestamp()]", ); }); test("should not add cache busting parameter when enableCacheBusting is false", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: false, }); const result = updateSrcPath("./script.js", "script"); // Should not include the cache busting parameter expect(result).toBe("/uxasset/externals/x_test_app/script.jsdbx"); expect(result).not.toContain("uxpcb="); }); test("should preserve query parameters from original path when enableCacheBusting is false", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: false, }); const result = updateSrcPath( "./script.js?param1=value1¶m2=value2", "script", ); // Should preserve original query parameters but not add cache busting expect(result).toBe( "/uxasset/externals/x_test_app/script.jsdbx?param1=value1¶m2=value2", ); expect(result).not.toContain("uxpcb="); }); test("should combine original query parameters with cache busting when enableCacheBusting is true", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: true, }); const result = updateSrcPath("./script.js?param1=value1", "script"); // Should include both original parameters and cache busting expect(result).toContain("/uxasset/externals/x_test_app/script.jsdbx?"); expect(result).toContain("param1=value1"); expect(result).toContain( "uxpcb=$[UxFrameworkScriptables.getFlushTimestamp()]", ); }); test("should respect preserveSrc when true", () => { const updateSrcPath = createUpdateSrcPathTest({ preserveSrc: true }); const result = updateSrcPath("./script.js", "script-abc123.js"); // Should return the emitted file name directly when preserveSrc is true expect(result).toBe("script-abc123.js"); expect(result).not.toContain("/uxasset/externals/"); expect(result).not.toContain("uxpcb="); }); test("should strip .jsdbx extension from an already-extended emitted filename", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: false, }); // rollup emits files with .jsdbx when outputOptions sets entryFileNames: "[name].jsdbx" const result = updateSrcPath("./script.js", "script.jsdbx"); expect(result).toBe("/uxasset/externals/x_test_app/script.jsdbx"); }); test("should preserve subdirectory structure from emitted filename in the uxasset path", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: false, }); const result = updateSrcPath( "./components/Button.tsx", "components/Button.jsdbx", ); expect(result).toBe( "/uxasset/externals/x_test_app/components/Button.jsdbx", ); }); test("should override existing uxpcb parameter with Jelly tag when enableCacheBusting is true", () => { const updateSrcPath = createUpdateSrcPathTest({ enableCacheBusting: true, }); const result = updateSrcPath("./script.js?uxpcb=123456789", "script"); // Should replace the existing uxpcb parameter with our Jelly tag expect(result).toContain("/uxasset/externals/x_test_app/script.jsdbx?"); expect(result).not.toContain("uxpcb=123456789"); expect(result).toContain( "uxpcb=$[UxFrameworkScriptables.getFlushTimestamp()]", ); }); }); describe("integration with react type", () => { const expectedReactPluginNames = [ "output-options", "html-script-entrypoints", "seismic", "replace", "url", "json", "css-url", "rollup-plugin-sass", "node-resolve", "collect-sn-translate", "swc", "swc-minify", "header", "sourcemap-url", ]; test("should return expected plugin names by default", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toEqual(expectedReactPluginNames); }); test("should return expected plugin names when type is react", async () => { const plugins = await servicenowFrontEndPlugins({ type: "react", scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toEqual(expectedReactPluginNames); }); test("should return expected plugin names when dev is true", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", dev: true, watchPaths: ["dist/static"], }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toEqual([ "header", "html-script-entrypoints", "seismic", "replace", "url", "json", "css-url", "rollup-plugin-sass", "node-resolve", "collect-sn-translate", "swc", "swc-minify", "header", "dev-server", "livereload", ]); }); test("should omit UXF globals header when omitDevUxGlobals is true in dev mode", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", dev: true, watchPaths: ["dist/static"], omitDevUxGlobals: true, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toEqual([ "html-script-entrypoints", "seismic", "replace", "url", "json", "css-url", "rollup-plugin-sass", "node-resolve", "collect-sn-translate", "swc", "swc-minify", "header", "dev-server", "livereload", ]); }); test("should proxy the default ServiceNow paths when a credential is provided", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", dev: true, watchPaths: ["dist/static"], credential: makeCredential(), }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toContain("dev-server"); expect(pluginNames).toContain("livereload"); }); }); describe("editableSourceCodeOnInstance option", () => { test("should not include source-embedding plugins by default (editableSourceCodeOnInstance defaults to false)", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).not.toContain("jsx-source"); expect(pluginNames).not.toContain("lit-template-injection"); expect(pluginNames).not.toContain("source-manifest"); }); test("should include litSource, jsxSource and uiPageSourceManifest when editableSourceCodeOnInstance is true", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", projectRootDir: "/project", registerExplicitId: () => "test-id", editableSourceCodeOnInstance: true, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toContain("jsx-source"); expect(pluginNames).not.toContain("lit-template-injection"); expect(pluginNames).toContain("source-manifest"); }); test("should throw when editableSourceCodeOnInstance is true but projectRootDir is missing", async () => { await expect( servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", registerExplicitId: () => "test-id", editableSourceCodeOnInstance: true, }), ).rejects.toThrow( "`projectRootDir` is required when `editableSourceCodeOnInstance` is true", ); }); test("should treat embedSourceCodeAndHints as a deprecated alias and warn", async () => { const warnSpy = jest.spyOn(console, "warn").mockImplementation(() => {}); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", projectRootDir: "/project", registerExplicitId: () => "test-id", embedSourceCodeAndHints: true, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toContain("jsx-source"); expect(pluginNames).not.toContain("lit-template-injection"); expect(pluginNames).not.toContain("source-manifest"); expect(warnSpy).toHaveBeenCalledWith( expect.stringContaining("`embedSourceCodeAndHints` is deprecated"), ); }); test("should include source-embedding plugins when editableSourceCodeOnInstance is an object", async () => { const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", projectRootDir: "/project", registerExplicitId: () => "test-id", editableSourceCodeOnInstance: { excludeSourcesPatterns: ["**/custom/**"], }, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toContain("jsx-source"); expect(pluginNames).not.toContain("lit-template-injection"); expect(pluginNames).toContain("source-manifest"); }); test("should throw when editableSourceCodeOnInstance is an object but projectRootDir is missing", async () => { await expect( servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", registerExplicitId: () => "test-id", editableSourceCodeOnInstance: { excludeSourcesPatterns: ["**/custom/**"], }, }), ).rejects.toThrow( "`projectRootDir` is required when `editableSourceCodeOnInstance` is true", ); }); test("should not throw when embedSourceCodeAndHints=true but projectRootDir is absent", async () => { jest.spyOn(console, "warn").mockImplementation(() => {}); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project/src/client", registerExplicitId: () => "test-id", embedSourceCodeAndHints: true, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).toContain("jsx-source"); expect(pluginNames).not.toContain("source-manifest"); }); test("should allow embedSourceCodeAndHints=false to disable source embedding", async () => { jest.spyOn(console, "warn").mockImplementation(() => {}); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", registerExplicitId: () => "test-id", embedSourceCodeAndHints: false, }); const pluginNames = (plugins as any[]) .flat() .map((p) => p?.name) .filter(Boolean); expect(pluginNames).not.toContain("jsx-source"); expect(pluginNames).not.toContain("lit-template-injection"); expect(pluginNames).not.toContain("source-manifest"); }); }); describe("registerExplicitId validation", () => { test("should throw when registerExplicitId is not provided and dev is false", async () => { await expect( servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", }), ).rejects.toThrow("registerExplicitId is required when dev is false"); }); test("should not throw when registerExplicitId is not provided and dev is true", async () => { await expect( servicenowFrontEndPlugins({ scope: "x_test_app", rootDir: "/project", dev: true, }), ).resolves.not.toThrow(); }); }); describe("sass extraction with pnpm-symlinked node_modules packages", () => { const findSassPlugin = (plugins: Plugin | Plugin[]) => (Array.isArray(plugins) ? plugins : [plugins]) .flat() .find((p) => p && p.name === "rollup-plugin-sass") as Plugin; // large enough compiled CSS to cross the 14KB extraction threshold // configured in servicenowFrontEndPlugins' shouldExtract const bigScss = Array.from( { length: 2000 }, (_, i) => `.a${i}{color:red}`, ).join("\n"); afterEach(() => { jest.restoreAllMocks(); }); test("rewrites a real (symlink-resolved) path through its node_modules symlink before emitting", async () => { const rootDir = "/project"; const emitFile = jest.fn(); const ctx = { addWatchFile: jest.fn(), emitFile, warn: jest.fn(), } as unknown as PluginContext; jest.spyOn(fs.promises, "readdir").mockImplementation(((dir: string) => { if (dir === path.join(rootDir, "node_modules")) { return Promise.resolve([ { name: "@pkg", isSymbolicLink: () => true }, ]); } return Promise.resolve([]); }) as unknown as typeof fs.promises.readdir); jest.spyOn(fs, "realpathSync").mockImplementation(((target: string) => { if (target === path.join(rootDir, "node_modules", "@pkg")) { return "/packages/react"; } return target; }) as unknown as typeof fs.realpathSync); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", }); const sassPlugin = findSassPlugin(plugins as Plugin[]); expect(sassPlugin).toBeDefined(); // no node_modules ancestor in this path, mirroring what pnpm // workspaces hand rollup after resolving the package symlink const filePath = "/packages/react/dist/Foo.scss"; await (sassPlugin.transform as any).call(ctx, bigScss, filePath); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); expect(emitFile).toHaveBeenCalledWith( expect.objectContaining({ fileName: "node_modules/@pkg/dist/Foo.css", }), ); }); test("resolves a symlink nested under a scoped (@scope/pkg) node_modules entry", async () => { const rootDir = "/project"; const emitFile = jest.fn(); const ctx = { addWatchFile: jest.fn(), emitFile, warn: jest.fn(), } as unknown as PluginContext; const nodeModulesDir = path.join(rootDir, "node_modules"); const scopeDir = path.join(nodeModulesDir, "@servicenow"); const linkPath = path.join(scopeDir, "some-pkg"); jest.spyOn(fs.promises, "readdir").mockImplementation(((dir: string) => { if (dir === nodeModulesDir) { return Promise.resolve([ { name: "@servicenow", isSymbolicLink: () => false }, ]); } if (dir === scopeDir) { return Promise.resolve([ { name: "some-pkg", isSymbolicLink: () => true }, ]); } return Promise.resolve([]); }) as unknown as typeof fs.promises.readdir); jest.spyOn(fs, "realpathSync").mockImplementation(((target: string) => { if (target === linkPath) { return "/packages/react"; } return target; }) as unknown as typeof fs.realpathSync); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", }); const sassPlugin = findSassPlugin(plugins as Plugin[]); const filePath = "/packages/react/dist/Foo.scss"; await (sassPlugin.transform as any).call(ctx, bigScss, filePath); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); expect(emitFile).toHaveBeenCalledWith( expect.objectContaining({ fileName: "node_modules/@servicenow/some-pkg/dist/Foo.css", }), ); }); test("walks up from a nested rootDir (client dir) to find node_modules at the app root", async () => { // Mirrors real now-sdk usage: servicenowFrontEndPlugins is called with // rootDir set to the client source directory (e.g. "src/client"), // which is nested below the app root where node_modules actually // lives, not a sibling of it. const appRoot = "/project"; const rootDir = path.join(appRoot, "src", "client"); const nodeModulesDir = path.join(appRoot, "node_modules"); const scopeDir = path.join(nodeModulesDir, "@servicenow"); const linkPath = path.join(scopeDir, "react-components"); const emitFile = jest.fn(); const ctx = { addWatchFile: jest.fn(), emitFile, warn: jest.fn(), } as unknown as PluginContext; jest.spyOn(fs.promises, "readdir").mockImplementation(((dir: string) => { if (dir === nodeModulesDir) { return Promise.resolve([ { name: "@servicenow", isSymbolicLink: () => false }, ]); } if (dir === scopeDir) { return Promise.resolve([ { name: "react-components", isSymbolicLink: () => true }, ]); } // No node_modules directly under rootDir or its intermediate // ancestors — only at the app root. const err: NodeJS.ErrnoException = new Error( `ENOENT: no such file or directory, scandir '${dir}'`, ); err.code = "ENOENT"; return Promise.reject(err); }) as unknown as typeof fs.promises.readdir); jest.spyOn(fs, "realpathSync").mockImplementation(((target: string) => { if (target === linkPath) { return "/packages/react"; } return target; }) as unknown as typeof fs.realpathSync); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", }); const sassPlugin = findSassPlugin(plugins as Plugin[]); const filePath = "/packages/react/dist/NowList.scss"; await (sassPlugin.transform as any).call(ctx, bigScss, filePath); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); expect(emitFile).toHaveBeenCalledWith( expect.objectContaining({ fileName: "node_modules/@servicenow/react-components/dist/NowList.css", }), ); }); test("falls back to a relative traversal when no symlink matches", async () => { const rootDir = "/project"; const emitFile = jest.fn(); const ctx = { addWatchFile: jest.fn(), emitFile, warn: jest.fn(), } as unknown as PluginContext; jest .spyOn(fs.promises, "readdir") .mockImplementation((() => Promise.resolve([])) as any); jest .spyOn(fs, "realpathSync") .mockImplementation(((target: string) => target) as any); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", }); const sassPlugin = findSassPlugin(plugins as Plugin[]); const filePath = "/packages/react/dist/Foo.scss"; await (sassPlugin.transform as any).call(ctx, bigScss, filePath); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); expect(emitFile).toHaveBeenCalledWith( expect.objectContaining({ fileName: "../packages/react/dist/Foo.css", }), ); }); test("scans node_modules for symlinks only once per build, not once per stylesheet", async () => { const rootDir = "/project"; const ctx = { addWatchFile: jest.fn(), emitFile: jest.fn(), warn: jest.fn(), } as unknown as PluginContext; const readdirSpy = jest .spyOn(fs.promises, "readdir") .mockImplementation((() => Promise.resolve([])) as any); jest .spyOn(fs, "realpathSync") .mockImplementation(((target: string) => target) as any); const plugins = await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", }); const sassPlugin = findSassPlugin(plugins as Plugin[]); await (sassPlugin.transform as any).call( ctx, bigScss, "/packages/react/dist/Foo.scss", ); await (sassPlugin.transform as any).call( ctx, bigScss, "/packages/other/dist/Bar.scss", ); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); const nodeModulesScans = readdirSpy.mock.calls.filter( ([dir]) => dir === path.join(rootDir, "node_modules"), ); expect(nodeModulesScans).toHaveLength(1); }); test("re-scans node_modules after buildStart, so the cache can't go stale across watch rebuilds", async () => { const rootDir = "/project"; const ctx = { addWatchFile: jest.fn(), emitFile: jest.fn(), warn: jest.fn(), } as unknown as PluginContext; const readdirSpy = jest .spyOn(fs.promises, "readdir") .mockImplementation((() => Promise.resolve([])) as any); jest .spyOn(fs, "realpathSync") .mockImplementation(((target: string) => target) as any); const plugins = (await servicenowFrontEndPlugins({ scope: "x_test_app", rootDir, registerExplicitId: () => "test-id", })) as Plugin[]; const sassPlugin = findSassPlugin(plugins); expect(sassPlugin.buildStart).toBeDefined(); await (sassPlugin.transform as any).call( ctx, bigScss, "/packages/react/dist/Foo.scss", ); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); const scansBeforeReset = readdirSpy.mock.calls.filter( ([dir]) => dir === path.join(rootDir, "node_modules"), ).length; expect(scansBeforeReset).toBe(1); // Simulate rollup starting a new (watch) rebuild, which reuses the // same plugin instances and thus the same closures. await (sassPlugin.buildStart as any).call(ctx); await (sassPlugin.transform as any).call( ctx, bigScss, "/packages/other/dist/Bar.scss", ); await (sassPlugin.generateBundle as any).call(ctx, {}, {}, true); const scansAfterReset = readdirSpy.mock.calls.filter( ([dir]) => dir === path.join(rootDir, "node_modules"), ).length; expect(scansAfterReset).toBe(2); }); }); });