-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This allows configuring Web Test Runner with Typescript, importing TypeScript/Sass files during tests for SSR and verifying the entry points from dist packages that import from `@sbb-esta/*`.
- Loading branch information
1 parent
f30a57b
commit 9b15570
Showing
21 changed files
with
558 additions
and
312 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v20.11.0 | ||
v22.2.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// @ts-check | ||
|
||
const dist = new URL('../../dist/', import.meta.url).href; | ||
|
||
/** | ||
* @param {string} specifier - The specifier of the resource to resolve. | ||
* @param {object} context - The context in which the resolve function is called. | ||
* @param {function} nextResolve - The function to call if nothing is done. | ||
* @returns {Promise} - A Promise that resolves with an object containing the format, shortCircuit flag, and url of the resource, | ||
* or rejects with an error. | ||
*/ | ||
export async function resolve(specifier, context, nextResolve) { | ||
if (specifier.startsWith('@sbb-esta/lyne-') && context.parentURL?.startsWith(dist)) { | ||
const aliasUrl = new URL(specifier.replace(/^@sbb-esta\/lyne-/, './'), dist).href; | ||
return { format: 'module', shortCircuit: true, url: aliasUrl }; | ||
} | ||
return nextResolve(specifier, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { register } from 'node:module'; | ||
|
||
register('./sass-hook.js', import.meta.url); | ||
register('./typescript-hook.js', import.meta.url); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// @ts-check | ||
|
||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { initCompiler } from 'sass'; | ||
|
||
const root = new URL('../../', import.meta.url).href; | ||
const sassCompiler = initCompiler(); | ||
const compileSass = (/** @type {string} */ fileUrl) => | ||
sassCompiler.compile(fileURLToPath(fileUrl), { | ||
loadPaths: ['.', './node_modules/'], | ||
}).css; | ||
|
||
/** | ||
* @param {string} url - The URL of the resource to load as a string. | ||
* @param {object} context - The context in which the load function is called. | ||
* @param {function} nextLoad - The function to call if this loader does nothing. | ||
* @returns {Promise} - A Promise that resolves with an object containing the format, shortCircuit flag, and source of the resource, | ||
* or rejects with an error. | ||
*/ | ||
export function load(url, context, nextLoad) { | ||
if (url.startsWith(root) && url.includes('.scss?')) { | ||
const source = `import { css } from 'lit';\nexport default css\`${compileSass(url)}\`;`; | ||
return Promise.resolve({ | ||
format: 'module', | ||
shortCircuit: true, | ||
source, | ||
}); | ||
} | ||
return nextLoad(url, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// @ts-check | ||
|
||
import { existsSync, readFileSync } from 'node:fs'; | ||
import { fileURLToPath } from 'node:url'; | ||
|
||
import { transform } from 'esbuild'; | ||
|
||
const root = new URL('../../', import.meta.url).href; | ||
const tsconfigRaw = readFileSync(new URL('./tsconfig.json', root), 'utf8'); | ||
|
||
/** | ||
* @param {string} specifier - The specifier of the resource to resolve. | ||
* @param {object} context - The context in which the resolve function is called. | ||
* @param {function} nextResolve - The function to call if nothing is done. | ||
* @returns {Promise} - A Promise that resolves with an object containing the format, shortCircuit flag, and url of the resource, | ||
* or rejects with an error. | ||
*/ | ||
export async function resolve(specifier, context, nextResolve) { | ||
if ( | ||
(specifier.startsWith('.') || specifier.startsWith(root)) && | ||
!specifier.includes('/node_modules/') && | ||
context.parentURL?.startsWith(root) | ||
) { | ||
const originalUrl = new URL(specifier, context.parentURL).href; | ||
const url = originalUrl.replace(/.js$/, '.ts'); | ||
if (!existsSync(fileURLToPath(originalUrl)) && existsSync(fileURLToPath(url))) { | ||
return { format: 'module', shortCircuit: true, url }; | ||
} | ||
} | ||
return nextResolve(specifier, context); | ||
} | ||
|
||
/** | ||
* @param {string} url - The URL of the resource to load as a string. | ||
* @param {object} context - The context in which the load function is called. | ||
* @param {function} nextLoad - The function to call if this loader does nothing. | ||
* @returns {Promise} - A Promise that resolves with an object containing the format, shortCircuit flag, and source of the resource, | ||
* or rejects with an error. | ||
*/ | ||
export async function load(url, context, nextLoad) { | ||
if (url.startsWith(root) && !url.includes('/node_modules/') && url.endsWith('.ts')) { | ||
const sourcefile = fileURLToPath(url); | ||
const content = readFileSync(sourcefile, 'utf8'); | ||
const result = await transform(content, { | ||
loader: 'ts', | ||
tsconfigRaw, | ||
/* | ||
TODO: sourcemap support does not seem to work, even with --enable-source-maps. Figure out why. | ||
sourcefile: url, | ||
sourcemap: 'inline', | ||
sourcesContent: false, | ||
*/ | ||
}); | ||
return { format: 'module', shortCircuit: true, source: result.code }; | ||
} | ||
return nextLoad(url, context); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
tools/web-test-runner/index.js → tools/web-test-runner/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,4 @@ | ||
/* eslint-disable import-x/export */ | ||
export * from './minimal-reporter.js'; | ||
export * from './patched-summary-reporter.js'; | ||
export * from './ssr-plugin.js'; | ||
export * from './visual-regression-plugin-config.js'; | ||
export * from './vite-plugin.js'; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.