2022-05-03 08:07:28 -05:00
|
|
|
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:07:28 -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',
|
|
|
|
]);
|
|
|
|
});
|
2022-05-03 08:07:28 -05:00
|
|
|
|
|
|
|
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:07:28 -05:00
|
|
|
},
|
2022-05-03 08:08:46 -05:00
|
|
|
dedupe: ['one', 'two'],
|
|
|
|
},
|
|
|
|
},
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
2022-05-03 08:08:46 -05:00
|
|
|
const [{ payload }] = events.eventCliSession(
|
|
|
|
{
|
|
|
|
cliCommand: 'dev',
|
|
|
|
astroVersion: '0.0.0',
|
|
|
|
},
|
|
|
|
config
|
|
|
|
);
|
2022-05-03 08:07:28 -05:00
|
|
|
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'],
|
2022-05-03 08:07:28 -05:00
|
|
|
},
|
|
|
|
css: {
|
|
|
|
modules: [],
|
2022-05-03 08:08:46 -05:00
|
|
|
postcss: {},
|
|
|
|
},
|
|
|
|
},
|
2022-05-03 08:07:28 -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([
|
|
|
|
'resolve',
|
|
|
|
'resolve.dedupe',
|
|
|
|
'css',
|
|
|
|
'css.modules',
|
|
|
|
'css.postcss',
|
|
|
|
]);
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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:07:28 -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([
|
|
|
|
'server',
|
|
|
|
'server.host',
|
|
|
|
'server.open',
|
|
|
|
'server.fs',
|
|
|
|
'server.fs.strict',
|
|
|
|
'server.fs.allow',
|
|
|
|
]);
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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:07:28 -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([
|
|
|
|
'build',
|
|
|
|
'build.target',
|
|
|
|
'build.outDir',
|
|
|
|
'build.cssTarget',
|
|
|
|
]);
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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:07:28 -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([
|
|
|
|
'preview',
|
|
|
|
'preview.host',
|
|
|
|
'preview.port',
|
|
|
|
'preview.another',
|
|
|
|
]);
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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:07:28 -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([
|
|
|
|
'optimizeDeps',
|
|
|
|
'optimizeDeps.entries',
|
|
|
|
'optimizeDeps.exclude',
|
|
|
|
]);
|
2022-05-03 08:07:28 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
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:07:28 -05:00
|
|
|
});
|
|
|
|
|
2022-05-03 08:08:46 -05:00
|
|
|
const [{ payload }] = events.eventCliSession(
|
|
|
|
{
|
|
|
|
cliCommand: 'dev',
|
|
|
|
astroVersion: '0.0.0',
|
|
|
|
},
|
|
|
|
config
|
|
|
|
);
|
2022-05-03 08:07:28 -05:00
|
|
|
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:07:28 -05:00
|
|
|
});
|
|
|
|
|
2022-05-03 08:08:46 -05:00
|
|
|
const [{ payload }] = events.eventCliSession(
|
|
|
|
{
|
|
|
|
cliCommand: 'dev',
|
|
|
|
astroVersion: '0.0.0',
|
|
|
|
},
|
|
|
|
config
|
|
|
|
);
|
2022-05-03 08:07:28 -05:00
|
|
|
expect(payload.config.viteKeys).is.deep.equal(['worker', 'worker.format', 'worker.plugins']);
|
|
|
|
});
|
|
|
|
});
|