diff --git a/src/elements/play-icon/play-icon.test.ts b/src/elements/play-icon/play-icon.test.ts new file mode 100644 index 0000000..bc6dd3d --- /dev/null +++ b/src/elements/play-icon/play-icon.test.ts @@ -0,0 +1,7 @@ +import {assert} from '@esm-bundle/chai' +import {PlayIcon} from './play-icon.js' + +test('tag is defined', () => { + const el = document.createElement('play-icon') + assert.instanceOf(el, PlayIcon) +}) diff --git a/src/utils/throttle.test.ts b/src/utils/throttle.test.ts index 63bde28..1b07f09 100644 --- a/src/utils/throttle.test.ts +++ b/src/utils/throttle.test.ts @@ -2,7 +2,7 @@ import {expect, test} from 'vitest' import {throttle} from './throttle.js' test('a throttled function is invoked with the latest arguments', async () => { - let out = {val: 0} + const out = {val: 0} const fn = throttle((val: number) => (out.val = val), 5) fn(1) expect(out.val).toBe(0) diff --git a/tools/build b/tools/build index 936cf81..ab84c8d 100755 --- a/tools/build +++ b/tools/build @@ -12,6 +12,7 @@ import {JSDOM} from 'jsdom' import fs from 'node:fs/promises' import path from 'node:path' import pkg from '../package.json' assert {type: 'json'} +import {esbuildConfig} from './esbuild-config.js' import {readTSDs} from './tsd.js' const watch = process.argv.includes('--watch') @@ -86,24 +87,11 @@ await fs.writeFile( /** @type {esbuild.BuildOptions} */ const opts = { + ...esbuildConfig(pkg.version, pkg.devDependencies['@devvit/public-api']), bundle: true, conditions: watch ? ['development'] : [], // Lit - define: { - 'globalThis.playVersion': `'${pkg.version}'`, - 'globalThis.devvitVersion': `'${pkg.devDependencies['@devvit/public-api']}'` - }, // See defines.d.ts. external: ['path'], // @typescript/vfs requires path. format: 'esm', - loader: { - '.css': 'text', - // Bundle templates for loading in pens and bundle pen worker as text so it - // can be loaded in a worker. - // Bundle templates for loading in pens and bundle pen worker as text so it - // can be loaded in a worker. - '.example.tsx': 'text', // should be dataurl + loaders.d.ts - '.svg': 'text', // should this be data url? - '.worker.min.js': 'text' - }, logLevel: `info`, // Print the port and build demarcations. sourcemap: 'linked', target: 'es2022' // https://esbuild.github.io/content-types/#tsconfig-json diff --git a/tools/esbuild-config.js b/tools/esbuild-config.js new file mode 100644 index 0000000..57a4d21 --- /dev/null +++ b/tools/esbuild-config.js @@ -0,0 +1,24 @@ +/** + * Just the configs that can be shared with test:ui. See + * https://modern-web.dev/docs/dev-server/plugins/esbuild. Note that esbuild + * uses `loader` whereas @web/dev-server-esbuild uses `loaders`. + * @arg {string} playVersion + * @arg {string} devvitVersion + * @ret {import('esbuild').BuildOptions} + */ +export function esbuildConfig(playVersion, devvitVersion) { + return { + define: { + 'globalThis.playVersion': `'${playVersion}'`, + 'globalThis.devvitVersion': `'${devvitVersion}'` + }, // See defines.d.ts. + loader: { + '.css': 'text', + // Bundle templates for loading in pens and bundle pen worker as text so it + // can be loaded in a worker. + '.example.tsx': 'text', + '.svg': 'text', + '.worker.min.js': 'text' + } + } +} diff --git a/web-test-runner.config.js b/web-test-runner.config.js index 6bf32db..fb6ae02 100644 --- a/web-test-runner.config.js +++ b/web-test-runner.config.js @@ -1,10 +1,19 @@ import {esbuildPlugin} from '@web/dev-server-esbuild' +import {esbuildConfig} from './tools/esbuild-config.js' + +const base = esbuildConfig('0.0.0', '0.0.1-next-2000-01-01-abcdef123.4') export default { files: ['src/elements/**/*.test.ts'], nodeResolve: true, plugins: [ - esbuildPlugin({ts: true, tsconfig: 'src/elements/test/tsconfig.json'}) + esbuildPlugin({ + ...base, + loaders: base.loader, + target: 'auto', + ts: true, + tsconfig: 'src/elements/test/tsconfig.json' + }) ], testFramework: { // https://mochajs.org/api/mocha