astro/packages/telemetry/test/session-event.test.js

482 lines
9 KiB
JavaScript
Raw Normal View History

import { expect } from 'chai';
import * as events from '../dist/events/index.js';
describe('Session event', () => {
describe('top-level', () => {
it('All top-level keys added', () => {
const config = {
root: 1,
srcDir: 2,
publicDir: 3,
outDir: 4,
site: 5,
base: 6,
trailingSlash: 7,
experimental: 8,
};
const expected = Object.keys(config);
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.configKeys).to.deep.equal(expected);
});
2022-05-03 13:08:46 +00:00
});
describe('config.build', () => {
it('configKeys includes format', () => {
const config = {
srcDir: 1,
build: {
format: 'file',
2022-05-06 13:23:09 +00:00
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.configKeys).to.deep.equal(['srcDir', 'build', 'build.format']);
});
it('config.build.format', () => {
const config = {
srcDir: 1,
build: {
format: 'file',
2022-05-06 13:23:09 +00:00
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.config.build.format).to.equal('file');
});
});
describe('config.server', () => {
it('configKeys includes server props', () => {
const config = {
srcDir: 1,
server: {
host: 'example.com',
2022-05-06 13:23:09 +00:00
port: 8033,
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.configKeys).to.deep.equal(['srcDir', 'server', 'server.host', 'server.port']);
});
});
describe('config.markdown', () => {
it('configKeys is deep', () => {
const config = {
publicDir: 1,
markdown: {
drafts: true,
mode: 'mdx',
shikiConfig: {
lang: 1,
theme: 2,
2022-05-06 13:23:09 +00:00
wrap: 3,
2022-05-03 13:08:46 +00:00
},
syntaxHighlight: 'shiki',
remarkPlugins: [],
rehypePlugins: [],
2022-05-06 13:23:09 +00:00
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
},
config
);
2022-05-06 13:23:09 +00:00
expect(payload.configKeys).to.deep.equal([
'publicDir',
'markdown',
'markdown.drafts',
'markdown.mode',
'markdown.shikiConfig',
'markdown.shikiConfig.lang',
'markdown.shikiConfig.theme',
'markdown.shikiConfig.wrap',
'markdown.syntaxHighlight',
'markdown.remarkPlugins',
'markdown.rehypePlugins',
]);
});
it('mode', () => {
const config = {
markdown: {
mode: 'mdx',
2022-05-06 13:23:09 +00:00
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.config.markdown.mode).to.equal('mdx');
});
it('syntaxHighlight', () => {
const config = {
markdown: {
syntaxHighlight: 'shiki',
2022-05-06 13:23:09 +00:00
},
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
2022-05-06 13:23:09 +00:00
astroVersion: '0.0.0',
},
config
);
expect(payload.config.markdown.syntaxHighlight).to.equal('shiki');
});
});
describe('config.vite', () => {
it('top-level keys are captured', async () => {
const config = {
root: 'some/thing',
vite: {
css: { modules: [] },
base: 'a',
mode: 'b',
define: {
2022-05-03 13:08:46 +00:00
a: 'b',
},
publicDir: 'some/dir',
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.configKeys).is.deep.equal([
'root',
'vite',
'vite.css',
'vite.css.modules',
'vite.base',
'vite.mode',
'vite.define',
'vite.publicDir',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.resolve keys are captured', async () => {
const config = {
vite: {
resolve: {
alias: {
a: 'b',
},
dedupe: ['one', 'two'],
},
2022-05-03 13:08:46 +00:00
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
2022-05-06 13:23:09 +00:00
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.resolve',
'vite.resolve.alias',
'vite.resolve.dedupe',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.css keys are captured', async () => {
const config = {
vite: {
resolve: {
dedupe: ['one', 'two'],
},
css: {
modules: [],
postcss: {},
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
2022-05-03 13:08:46 +00:00
},
config
);
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.resolve',
'vite.resolve.dedupe',
'vite.css',
'vite.css.modules',
'vite.css.postcss',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.server keys are captured', async () => {
const config = {
vite: {
server: {
host: 'example.com',
open: true,
fs: {
strict: true,
allow: ['a', 'b'],
},
},
2022-05-03 13:08:46 +00:00
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.server',
'vite.server.host',
'vite.server.open',
'vite.server.fs',
'vite.server.fs.strict',
'vite.server.fs.allow',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.build keys are captured', async () => {
const config = {
vite: {
build: {
target: 'one',
outDir: 'some/dir',
cssTarget: {
one: 'two',
},
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.build',
'vite.build.target',
'vite.build.outDir',
'vite.build.cssTarget',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.preview keys are captured', async () => {
const config = {
vite: {
preview: {
host: 'example.com',
port: 8080,
another: {
a: 'b',
},
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.preview',
'vite.preview.host',
'vite.preview.port',
'vite.preview.another',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.optimizeDeps keys are captured', async () => {
const config = {
vite: {
optimizeDeps: {
entries: ['one', 'two'],
exclude: ['secret', 'name'],
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.optimizeDeps',
'vite.optimizeDeps.entries',
'vite.optimizeDeps.exclude',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.ssr keys are captured', async () => {
const config = {
vite: {
ssr: {
external: ['a'],
target: { one: 'two' },
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
2022-05-06 13:23:09 +00:00
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.ssr',
'vite.ssr.external',
'vite.ssr.target',
]);
});
2022-05-06 13:23:09 +00:00
it('vite.worker keys are captured', async () => {
const config = {
vite: {
worker: {
format: { a: 'b' },
plugins: ['a', 'b'],
},
},
};
2022-05-06 13:23:09 +00:00
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
2022-05-06 13:23:09 +00:00
expect(payload.configKeys).is.deep.equal([
'vite',
'vite.worker',
'vite.worker.format',
'vite.worker.plugins',
]);
});
});
describe('config.integrations + optionalIntegrations', () => {
it('optional/conditional integrations', () => {
const config = {
srcDir: 1,
2022-06-16 18:54:57 +00:00
integrations: [null, undefined, { name: 'example-integration' }],
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
2022-06-16 18:54:57 +00:00
expect(payload.config.integrations).deep.equal(['example-integration']);
expect(payload.optionalIntegrations).to.equal(2);
2022-06-16 18:54:57 +00:00
});
it('falsy integrations', () => {
const config = {
srcDir: 1,
2022-06-16 18:54:57 +00:00
integrations: [null, undefined, false],
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config
);
expect(payload.config.integrations.length).to.equal(0);
expect(payload.optionalIntegrations).to.equal(3);
});
});
describe('flags', () => {
it('includes cli flags in payload', () => {
const config = {};
const flags = {
root: 'root',
site: 'http://example.com',
host: true,
port: 8080,
config: 'path/to/config.mjs',
experimentalSsr: true,
experimentalIntegrations: true,
drafts: true,
2022-05-06 13:23:09 +00:00
};
const [{ payload }] = events.eventCliSession(
{
cliCommand: 'dev',
astroVersion: '0.0.0',
},
config,
flags
);
expect(payload.flags).to.deep.equal([
'root',
'site',
'host',
'port',
'config',
'experimentalSsr',
'experimentalIntegrations',
2022-05-06 13:23:09 +00:00
'drafts',
]);
2022-05-06 13:23:09 +00:00
});
});
});