build: add Vue and Pinia to the browser build and unit tests

This commit is contained in:
Sameh Khamis committed 2026-10-30 16:07:44 -07:00
1 parent 6d6df9d83b
commit c13c487dcf
8 files changed
+658 -20

No files matched your search

+4
View File
@@ -0,0 +1,4 @@
import { register } from 'node:module';
// Lets unit tests import single-file components (`node --import`).
register('./vueLoader.mjs', import.meta.url);
+39
View File
@@ -0,0 +1,39 @@
import { readFile } from 'node:fs/promises';
import { fileURLToPath } from 'node:url';
import { compileScript, compileTemplate, parse } from 'vue/compiler-sfc';
/**
* Compile a single-file component to an ES module for Node's test runner.
* Styles are dropped: tests read the global stylesheet separately.
*/
export function compileVueModule(source, filename) {
const { descriptor, errors } = parse(source, { filename });
if (errors.length) throw errors[0];
const id = filename;
if (descriptor.scriptSetup) {
return compileScript(descriptor, { id, inlineTemplate: true }).content;
}
const script = descriptor.script
? compileScript(descriptor, { id }).content.replace(
'export default',
'const __sfc__ =',
)
: 'const __sfc__ = {};';
const template = descriptor.template
? compileTemplate({ source: descriptor.template.content, filename, id })
.code
: '';
return `${script}\n${template}\n__sfc__.render = typeof render === 'function' ? render : __sfc__.render;\nexport default __sfc__;\n`;
}
/** Node module hook: load `.vue` files as compiled modules. */
export async function load(url, context, nextLoad) {
if (!url.endsWith('.vue')) return nextLoad(url, context);
const filename = fileURLToPath(url);
const source = await readFile(filename, 'utf8');
return {
format: 'module',
source: compileVueModule(source, filename),
shortCircuit: true,
};
}
+4 -3
View File
@@ -29,7 +29,8 @@ test('explicit build inputs preserve browser-only defines, plugin order and loop
assert.equal(config.plugins[0].enforce, 'pre');
assert.equal(config.plugins[1].name, 'host-check');
assert.equal(config.plugins[1].enforce, 'pre');
assert.equal(config.plugins[4], plugin);
assert.equal(config.plugins[4].name, 'vite:vue');
assert.equal(config.plugins[5], plugin);
assert.equal(config.server.host, 'localhost');
assert.equal(config.server.port, 4173);
assert.deepEqual(config.server.allowedHosts, ['localhost', '127.0.0.1']);
@@ -103,7 +104,7 @@ test('build helper does not discover environment values or construct local provi
undefined,
);
assert.deepEqual(
config.plugins.slice(4).map((plugin) => plugin.name),
config.plugins.slice(5).map((plugin) => plugin.name),
['embed-framing', 'panel-build'],
);
} finally {
@@ -117,7 +118,7 @@ test('root config retains existing named exports and standalone provider order',
assert.equal(compatibility[name], value, name);
const config = standaloneConfig({ mode: 'test' });
const standaloneProviders = config.plugins
.slice(4, -6)
.slice(5, -6)
.map((plugin) => plugin.name);
assert.equal(
standaloneProviders.filter((name) => name === 'gemini-live-proxy').length,