0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-23 21:53:55 -05:00
astro/packages/telemetry/test/session-event.test.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

242 lines
4.3 KiB
JavaScript
Raw Normal View History

import { expect } from 'chai';
import * as events from '../dist/events/index.js';
import { resolveConfig } from '../../astro/dist/core/config.js';
async function mockConfig(userConfig) {
return await resolveConfig(userConfig, import.meta.url, {}, 'dev');
}
describe('Session event', () => {
it('top-level keys are captured', async () => {
const config = await mockConfig({
vite: {
css: { modules: [] },
base: 'a',
mode: 'b',
define: {
a: 'b',
},
publicDir: 'some/dir',
2022-05-03 08:08:46 -05:00
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'css',
'css.modules',
'base',
'mode',
'define',
'publicDir',
]);
});
it('vite.resolve keys are captured', async () => {
const config = await mockConfig({
vite: {
resolve: {
alias: {
2022-05-03 08:08:46 -05:00
a: 'b',
},
2022-05-03 08:08:46 -05:00
dedupe: ['one', 'two'],
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal(['resolve', 'resolve.alias', 'resolve.dedupe']);
});
it('vite.css keys are captured', async () => {
const config = await mockConfig({
vite: {
resolve: {
2022-05-03 08:08:46 -05:00
dedupe: ['one', 'two'],
},
css: {
modules: [],
2022-05-03 08:08:46 -05:00
postcss: {},
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'resolve',
'resolve.dedupe',
'css',
'css.modules',
'css.postcss',
]);
});
it('vite.server keys are captured', async () => {
const config = await mockConfig({
vite: {
server: {
host: 'example.com',
open: true,
fs: {
strict: true,
2022-05-03 08:08:46 -05:00
allow: ['a', 'b'],
},
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'server',
'server.host',
'server.open',
'server.fs',
'server.fs.strict',
'server.fs.allow',
]);
});
it('vite.build keys are captured', async () => {
const config = await mockConfig({
vite: {
build: {
target: 'one',
outDir: 'some/dir',
cssTarget: {
2022-05-03 08:08:46 -05:00
one: 'two',
},
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'build',
'build.target',
'build.outDir',
'build.cssTarget',
]);
});
it('vite.preview keys are captured', async () => {
const config = await mockConfig({
vite: {
preview: {
host: 'example.com',
port: 8080,
another: {
2022-05-03 08:08:46 -05:00
a: 'b',
},
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'preview',
'preview.host',
'preview.port',
'preview.another',
]);
});
it('vite.optimizeDeps keys are captured', async () => {
const config = await mockConfig({
vite: {
optimizeDeps: {
entries: ['one', 'two'],
2022-05-03 08:08:46 -05:00
exclude: ['secret', 'name'],
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal([
'optimizeDeps',
'optimizeDeps.entries',
'optimizeDeps.exclude',
]);
});
it('vite.ssr keys are captured', async () => {
const config = await mockConfig({
vite: {
ssr: {
external: ['a'],
2022-05-03 08:08:46 -05:00
target: { one: 'two' },
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal(['ssr', 'ssr.external', 'ssr.target']);
});
it('vite.worker keys are captured', async () => {
const config = await mockConfig({
vite: {
worker: {
format: { a: 'b' },
2022-05-03 08:08:46 -05:00
plugins: ['a', 'b'],
},
},
});
2022-05-03 08:08:46 -05:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.viteKeys).is.deep.equal(['worker', 'worker.format', 'worker.plugins']);
});
});