browsertrix/frontend/web-test-runner.config.mjs
Emma Segal-Grossman 683e531cc0
Localize durations on frontend (#2196)
Partially addresses
https://github.com/webrecorder/browsertrix/issues/2171

- [x] Reimplement `pretty-ms`'s rounding logic to convert to a
`Intl.DurationFormat`-compatible object
- [x] Add `localize.duration` and `localize.humanizeDuration` methods
- [x] Replace `pretty-ms` usage with localized formatting
- [x] Add `Intl.DurationFormat` polyfill
- [x] Update localize tests
- [x] Fix broken tests (thank you @SuaYoo!)
- This looks to be possibly a bug somewhere in the web test runner's
code? Have yet to figure this one out
- Might be related to these:
https://github.com/web-dev-server/web-dev-server/issues/1
https://github.com/guybedford/es-module-lexer/issues/82 — both closed
with no comments or resolution 🙃 — `es-module-lexer` seems to be most
likely, given it's a native module & might be handling unicode sequences
incorrectly or not at all?
- [x] Clean up messy `index.d.ts` — probably split this out? The
definitions haven't yet made their way into `esnext`
https://github.com/microsoft/TypeScript/issues/60608

---------

Co-authored-by: emma-sg <emma-sg@users.noreply.github.com>
Co-authored-by: sua yoo <sua@suayoo.com>
2024-12-03 16:46:57 -05:00

92 lines
2.8 KiB
JavaScript

/* eslint-env node */
import { fileURLToPath } from "url";
import commonjsPlugin from "@rollup/plugin-commonjs";
import { esbuildPlugin } from "@web/dev-server-esbuild";
import { importMapsPlugin } from "@web/dev-server-import-maps";
import { fromRollup } from "@web/dev-server-rollup";
import { playwrightLauncher } from "@web/test-runner-playwright";
import glob from "glob";
import { typescriptPaths as typescriptPathsPlugin } from "rollup-plugin-typescript-paths";
const commonjs = fromRollup(commonjsPlugin);
const typescriptPaths = fromRollup(typescriptPathsPlugin);
// Map css and assert imports to mock file
const emptyImports = {};
glob.sync("./src/**/*.css").forEach((filepath) => {
emptyImports[filepath] = fileURLToPath(
new URL("./src/__mocks__/_empty.js", import.meta.url),
);
});
glob.sync("./src/assets/**/*").forEach((filepath) => {
// Enable "~assets" imports, which doesn't work with `rollup-plugin-typescript-paths`
const aliasedImportPath = filepath.replace("./src/", "~");
emptyImports[aliasedImportPath] = fileURLToPath(
new URL("./src/__mocks__/_empty.js", import.meta.url),
);
});
export default {
nodeResolve: true,
rootDir: process.cwd(),
browsers: [
playwrightLauncher({
product: "chromium",
launchOptions: {
channel: "chromium",
},
async createBrowserContext({ browser }) {
return browser.newContext({ timezoneId: "Pacific/Easter" });
},
}),
],
plugins: [
typescriptPaths({
preserveExtensions: true,
absolute: false,
nonRelative: true, // needed for non-ts files
transform(path) {
return `/${path}`;
},
}),
esbuildPlugin({
ts: true,
tsconfig: fileURLToPath(new URL("./tsconfig.json", import.meta.url)),
target: "esnext",
}),
commonjs({
include: [
// web-test-runner expects es modules,
// include umd/commonjs modules here:
"node_modules/url-pattern/**/*",
"node_modules/lodash/**/*",
"node_modules/color/**/*",
"node_modules/slugify/**/*",
"node_modules/parse-ms/**/*",
"node_modules/regex-colorize/**/*",
"node_modules/@formatjs/intl-durationformat/**/*",
],
}),
importMapsPlugin({
inject: {
importMap: {
imports: {
...emptyImports,
"./src/shoelace": fileURLToPath(
new URL("./src/__mocks__/shoelace.js", import.meta.url),
),
"tailwindcss/tailwind.css": fileURLToPath(
new URL("./src/__mocks__/_empty.js", import.meta.url),
),
"@shoelace-style/shoelace/dist/themes/light.css": fileURLToPath(
new URL("./src/__mocks__/_empty.js", import.meta.url),
),
},
},
},
}),
],
};