kempo-testing-framework 1.4.11 → 1.4.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "kempo-testing-framework",
3
- "version": "1.4.11",
3
+ "version": "1.4.12",
4
4
  "description": "The Kempo Testing Framework is a simple testing framework built on the principle that code intended to be ran in the browser should be tested in the browser, code intended to be ran in Node should be tested in Node, and code intended to be ran in both should be tested in both. No mocking, no complexity—just testing.",
5
5
  "main": "index.js",
6
6
  "bin": {
@@ -3,6 +3,7 @@ import puppeteer from 'puppeteer';
3
3
  import LOG_LEVELS from './utils/logLevels.js';
4
4
  import path from 'path';
5
5
  import { fileURLToPath } from 'url';
6
+ import { readFile } from 'fs/promises';
6
7
 
7
8
  export default async ({
8
9
  testFile,
@@ -27,13 +28,18 @@ export default async ({
27
28
  const __filename = fileURLToPath(import.meta.url);
28
29
  const __dirname = path.dirname(__filename);
29
30
 
30
- // Load the test module to check for 'page' export
31
+ // Detect a custom `page` export with a static text scan rather than importing the module in Node
32
+ // — a browser test file can freely import browser-only absolute specifiers (e.g. "/kempo-ui/...",
33
+ // meant to be resolved by an import map once actually loaded in the browser), which Node's own
34
+ // module resolver can't follow. Dynamically importing it here to peek at one export would throw on
35
+ // exactly those files and silently fall back to the default page instead of the one they asked for.
31
36
  let customPage = null;
32
37
  try {
33
38
  const testFilePath = path.resolve(process.cwd(), testFile.replace(/\//g, path.sep));
34
- const testModule = await import(`file://${testFilePath}`);
35
- if (typeof testModule.page === 'string') {
36
- customPage = testModule.page;
39
+ const source = await readFile(testFilePath, 'utf8');
40
+ const match = source.match(/export\s+const\s+page\s*=\s*(['"])((?:(?!\1).)*)\1/);
41
+ if (match) {
42
+ customPage = match[2];
37
43
  }
38
44
  } catch (e) {
39
45
  // Ignore errors, fallback to default page
@@ -89,7 +95,7 @@ export default async ({
89
95
  content: `
90
96
  (async () => {
91
97
  try {
92
- const runTestsModule = await import('/src/runTests.js');
98
+ const runTestsModule = await import('/runTests.js');
93
99
  const urlParams = new URLSearchParams(window.location.search);
94
100
  const testFile = urlParams.get('testFile') || '${testFile}';
95
101
  const testFilter = urlParams.get('testFilter') || '';