|
1 | 1 | const { execFileSync } = require("child_process") |
2 | 2 | const { |
3 | | - existsSync, |
4 | 3 | mkdtempSync, |
5 | 4 | readFileSync, |
6 | 5 | rmSync, |
@@ -99,17 +98,41 @@ describe("compiled package output", () => { |
99 | 98 | staticExportNames.forEach((name) => { |
100 | 99 | expect(compiled).toContain(`exports.${name} =`) |
101 | 100 | }) |
| 101 | + |
| 102 | + const source = readFileSync( |
| 103 | + join(process.cwd(), "package", "index.ts"), |
| 104 | + "utf8" |
| 105 | + ) |
| 106 | + const shakapackerObject = source.match( |
| 107 | + /const shakapacker = \{([\s\S]*?)\n\}/ |
| 108 | + )[1] |
| 109 | + const webpackMergeStaticExportNames = [ |
| 110 | + "merge", |
| 111 | + "mergeWithCustomize", |
| 112 | + "mergeWithRules", |
| 113 | + "unique" |
| 114 | + ] |
| 115 | + const sourceNonLazyExportNames = [ |
| 116 | + ...Array.from( |
| 117 | + shakapackerObject.matchAll(/^\s{2}([A-Za-z]\w*),$/gm), |
| 118 | + (match) => match[1] |
| 119 | + ), |
| 120 | + ...webpackMergeStaticExportNames |
| 121 | + ] |
| 122 | + expect([...staticExportNames].sort()).toStrictEqual( |
| 123 | + sourceNonLazyExportNames.sort() |
| 124 | + ) |
| 125 | + |
102 | 126 | expect(compiled).not.toMatch(/exports\.(baseConfig|rules)\s*=/) |
103 | 127 | }) |
104 | 128 |
|
105 | | - // symlinkSync to node_modules/lib requires elevated privileges on Windows |
106 | | - // (EPERM), so the native-ESM consumer specs are skipped there; the |
107 | | - // declaration-emit test above does not symlink and still runs. |
| 129 | + // symlinkSync requires elevated privileges on Windows (EPERM), so the |
| 130 | + // native-ESM consumer specs are skipped there; the declaration-emit test above |
| 131 | + // does not symlink and still runs. |
108 | 132 | const describeOrSkip = process.platform === "win32" ? describe.skip : describe |
109 | 133 | const libDir = join(process.cwd(), "lib") |
110 | | - const describeOrSkipLib = existsSync(libDir) ? describeOrSkip : describe.skip |
111 | 134 |
|
112 | | - describeOrSkipLib("native ESM consumers", () => { |
| 135 | + describeOrSkip("native ESM consumers", () => { |
113 | 136 | beforeAll(() => { |
114 | 137 | symlinkSync( |
115 | 138 | join(process.cwd(), "node_modules"), |
|
0 commit comments