Refactor some integration tests (#7303)
This commit is contained in:
parent
a4176f98b8
commit
9c525d3f11
12 changed files with 197 additions and 185 deletions
|
@ -51,7 +51,7 @@ describe('getStaticPaths - dev calls', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
devServer.stop();
|
await devServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls getStaticPaths once', async () => {
|
it('only calls getStaticPaths once', async () => {
|
||||||
|
|
|
@ -3,14 +3,20 @@ import * as cheerio from 'cheerio';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
import addClasses from './fixtures/astro-markdown-plugins/add-classes.mjs';
|
import addClasses from './fixtures/astro-markdown-plugins/add-classes.mjs';
|
||||||
|
|
||||||
async function buildFixture(config) {
|
const defaultMarkdownConfig = {
|
||||||
const fixture = await loadFixture({
|
gfm: true,
|
||||||
root: './fixtures/astro-markdown-plugins/',
|
smartypants: true,
|
||||||
...config,
|
remarkPlugins: [
|
||||||
});
|
remarkExamplePlugin,
|
||||||
await fixture.build();
|
'remark-code-titles',
|
||||||
return fixture;
|
['rehype-autolink-headings', { behavior: 'prepend' }],
|
||||||
}
|
],
|
||||||
|
rehypePlugins: [
|
||||||
|
'rehype-slug',
|
||||||
|
['rehype-toc', { headings: ['h2', 'h3'] }],
|
||||||
|
[addClasses, { 'h1,h2,h3': 'title' }],
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
function remarkExamplePlugin() {
|
function remarkExamplePlugin() {
|
||||||
return (tree) => {
|
return (tree) => {
|
||||||
|
@ -22,20 +28,18 @@ function remarkExamplePlugin() {
|
||||||
}
|
}
|
||||||
|
|
||||||
describe('Astro Markdown plugins', () => {
|
describe('Astro Markdown plugins', () => {
|
||||||
it('Can render markdown with plugins', async () => {
|
describe('Default test plugins', () => {
|
||||||
const fixture = await buildFixture({
|
let fixture;
|
||||||
markdown: {
|
|
||||||
remarkPlugins: [
|
before(async () => {
|
||||||
'remark-code-titles',
|
fixture = await loadFixture({
|
||||||
['rehype-autolink-headings', { behavior: 'prepend' }],
|
root: './fixtures/astro-markdown-plugins/',
|
||||||
],
|
markdown: defaultMarkdownConfig,
|
||||||
rehypePlugins: [
|
|
||||||
'rehype-slug',
|
|
||||||
['rehype-toc', { headings: ['h2', 'h3'] }],
|
|
||||||
[addClasses, { 'h1,h2,h3': 'title' }],
|
|
||||||
],
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
|
await fixture.build();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('Can render markdown with plugins', async () => {
|
||||||
const html = await fixture.readFile('/index.html');
|
const html = await fixture.readFile('/index.html');
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
@ -48,12 +52,6 @@ describe('Astro Markdown plugins', () => {
|
||||||
|
|
||||||
// Asserts Astro 1.0 behavior is removed. Test can be removed in Astro 3.0.
|
// Asserts Astro 1.0 behavior is removed. Test can be removed in Astro 3.0.
|
||||||
it('Still applies default plugins when user plugins are provided', async () => {
|
it('Still applies default plugins when user plugins are provided', async () => {
|
||||||
const fixture = await buildFixture({
|
|
||||||
markdown: {
|
|
||||||
remarkPlugins: [remarkExamplePlugin],
|
|
||||||
rehypePlugins: [[addClasses, { 'h1,h2,h3': 'title' }]],
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const gfmHtml = await fixture.readFile('/with-gfm/index.html');
|
const gfmHtml = await fixture.readFile('/with-gfm/index.html');
|
||||||
const $1 = cheerio.load(gfmHtml);
|
const $1 = cheerio.load(gfmHtml);
|
||||||
expect($1('a[href="https://example.com"]')).to.have.lengthOf(1);
|
expect($1('a[href="https://example.com"]')).to.have.lengthOf(1);
|
||||||
|
@ -66,53 +64,60 @@ describe('Astro Markdown plugins', () => {
|
||||||
testRehype(gfmHtml, '#github-flavored-markdown-test');
|
testRehype(gfmHtml, '#github-flavored-markdown-test');
|
||||||
});
|
});
|
||||||
|
|
||||||
for (const gfm of [true, false]) {
|
it(`Handles GFM when gfm = true`, async () => {
|
||||||
it(`Handles GFM when gfm = ${gfm}`, async () => {
|
|
||||||
const fixture = await buildFixture({
|
|
||||||
markdown: {
|
|
||||||
remarkPlugins: [remarkExamplePlugin],
|
|
||||||
rehypePlugins: [[addClasses, { 'h1,h2,h3': 'title' }]],
|
|
||||||
gfm,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const html = await fixture.readFile('/with-gfm/index.html');
|
const html = await fixture.readFile('/with-gfm/index.html');
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
// test 1: GFM autolink applied correctly
|
// test 1: GFM autolink applied correctly
|
||||||
if (gfm === true) {
|
|
||||||
expect($('a[href="https://example.com"]')).to.have.lengthOf(1);
|
expect($('a[href="https://example.com"]')).to.have.lengthOf(1);
|
||||||
} else {
|
|
||||||
expect($('a[href="https://example.com"]')).to.have.lengthOf(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
testRemark(html);
|
testRemark(html);
|
||||||
testRehype(html, '#github-flavored-markdown-test');
|
testRehype(html, '#github-flavored-markdown-test');
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
for (const smartypants of [true, false]) {
|
it(`Handles SmartyPants when smartypants = true`, async () => {
|
||||||
it(`Handles SmartyPants when smartypants = ${smartypants}`, async () => {
|
|
||||||
const fixture = await buildFixture({
|
|
||||||
markdown: {
|
|
||||||
remarkPlugins: [remarkExamplePlugin],
|
|
||||||
rehypePlugins: [[addClasses, { 'h1,h2,h3': 'title' }]],
|
|
||||||
smartypants,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
const html = await fixture.readFile('/with-smartypants/index.html');
|
const html = await fixture.readFile('/with-smartypants/index.html');
|
||||||
const $ = cheerio.load(html);
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
// test 1: GFM autolink applied correctly
|
// test 1: smartypants applied correctly
|
||||||
if (smartypants === true) {
|
|
||||||
expect($('p').html()).to.equal('“Smartypants” is — awesome');
|
expect($('p').html()).to.equal('“Smartypants” is — awesome');
|
||||||
} else {
|
|
||||||
expect($('p').html()).to.equal('"Smartypants" is -- awesome');
|
|
||||||
}
|
|
||||||
|
|
||||||
testRemark(html);
|
testRemark(html);
|
||||||
testRehype(html, '#smartypants-test');
|
testRehype(html, '#smartypants-test');
|
||||||
});
|
});
|
||||||
}
|
});
|
||||||
|
|
||||||
|
it(`Handles GFM when gfm = false`, async () => {
|
||||||
|
const fixture = await loadFixture({
|
||||||
|
root: './fixtures/astro-markdown-plugins/',
|
||||||
|
markdown: { ...defaultMarkdownConfig, gfm: false },
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
|
||||||
|
const html = await fixture.readFile('/with-gfm/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
expect($('a[href="https://example.com"]')).to.have.lengthOf(0);
|
||||||
|
|
||||||
|
testRemark(html);
|
||||||
|
testRehype(html, '#github-flavored-markdown-test');
|
||||||
|
});
|
||||||
|
|
||||||
|
it(`Handles SmartyPants when smartypants = false`, async () => {
|
||||||
|
const fixture = await loadFixture({
|
||||||
|
root: './fixtures/astro-markdown-plugins/',
|
||||||
|
markdown: { ...defaultMarkdownConfig, smartypants: false },
|
||||||
|
});
|
||||||
|
await fixture.build();
|
||||||
|
|
||||||
|
const html = await fixture.readFile('/with-smartypants/index.html');
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
|
||||||
|
expect($('p').html()).to.equal('"Smartypants" is -- awesome');
|
||||||
|
|
||||||
|
testRemark(html);
|
||||||
|
testRehype(html, '#smartypants-test');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
function testRehype(html, headingId) {
|
function testRehype(html, headingId) {
|
||||||
|
|
|
@ -183,23 +183,3 @@ describe('astro cli', () => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('astro cli i18n', () => {
|
|
||||||
const LOCALES = ['en_US', 'sv_SE', 'es_419.UTF-8', 'es_ES@euro', 'C'];
|
|
||||||
LOCALES.forEach((locale) => {
|
|
||||||
it(`astro does NOT throw on "${locale}" locales`, async () => {
|
|
||||||
const projectRootURL = new URL('./fixtures/astro-basic/', import.meta.url);
|
|
||||||
let error = null;
|
|
||||||
try {
|
|
||||||
const proc = cli('dev', '--root', fileURLToPath(projectRootURL), {
|
|
||||||
env: { LANG: locale },
|
|
||||||
});
|
|
||||||
await parseCliDevStart(proc);
|
|
||||||
} catch (e) {
|
|
||||||
console.log(e);
|
|
||||||
error = e.message;
|
|
||||||
}
|
|
||||||
expect(error).to.be.null;
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import { expect } from 'chai';
|
import { expect } from 'chai';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture, silentLogging } from './test-utils.js';
|
||||||
import testAdapter from './test-adapter.js';
|
import testAdapter from './test-adapter.js';
|
||||||
import { nodeLogDestination } from '../dist/core/logger/node.js';
|
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
|
|
||||||
describe('Astro.clientAddress', () => {
|
describe('Astro.clientAddress', () => {
|
||||||
|
@ -110,11 +109,7 @@ describe('Astro.clientAddress', () => {
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
// We expect an error, so silence the output
|
// We expect an error, so silence the output
|
||||||
const logging = {
|
devServer = await fixture.startDevServer({ logging: silentLogging });
|
||||||
dest: nodeLogDestination,
|
|
||||||
level: 'silent',
|
|
||||||
};
|
|
||||||
devServer = await fixture.startDevServer({ logging });
|
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
|
|
|
@ -2,10 +2,10 @@ import { expect } from 'chai';
|
||||||
import * as cheerio from 'cheerio';
|
import * as cheerio from 'cheerio';
|
||||||
import { basename } from 'node:path';
|
import { basename } from 'node:path';
|
||||||
import { Writable } from 'node:stream';
|
import { Writable } from 'node:stream';
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { removeDir } from '../dist/core/fs/index.js';
|
import { removeDir } from '../dist/core/fs/index.js';
|
||||||
import testAdapter from './test-adapter.js';
|
import testAdapter from './test-adapter.js';
|
||||||
import { loadFixture } from './test-utils.js';
|
import { loadFixture } from './test-utils.js';
|
||||||
|
import { testImageService } from './test-image-service.js';
|
||||||
|
|
||||||
describe('astro:image', () => {
|
describe('astro:image', () => {
|
||||||
/** @type {import('./test-utils').Fixture} */
|
/** @type {import('./test-utils').Fixture} */
|
||||||
|
@ -23,6 +23,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService({ foo: 'bar' }),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
devServer = await fixture.startDevServer({
|
devServer = await fixture.startDevServer({
|
||||||
|
@ -377,6 +380,32 @@ describe('astro:image', () => {
|
||||||
expect($('img').attr('src').includes('/src')).to.equal(true);
|
expect($('img').attr('src').includes('/src')).to.equal(true);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('custom service', () => {
|
||||||
|
it('custom service implements getHTMLAttributes', async () => {
|
||||||
|
const response = await fixture.fetch('/');
|
||||||
|
const html = await response.text();
|
||||||
|
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('#local img').attr('data-service')).to.equal('my-custom-service');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('custom service works in Markdown', async () => {
|
||||||
|
const response = await fixture.fetch('/post');
|
||||||
|
const html = await response.text();
|
||||||
|
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('img').attr('data-service')).to.equal('my-custom-service');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('gets service config', async () => {
|
||||||
|
const response = await fixture.fetch('/');
|
||||||
|
const html = await response.text();
|
||||||
|
|
||||||
|
const $ = cheerio.load(html);
|
||||||
|
expect($('#local img').attr('data-service-config')).to.equal('bar');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('proper errors', () => {
|
describe('proper errors', () => {
|
||||||
|
@ -391,6 +420,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
devServer = await fixture.startDevServer({
|
devServer = await fixture.startDevServer({
|
||||||
|
@ -456,6 +488,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
base: '/blog',
|
base: '/blog',
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
@ -509,6 +544,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
base: '/blog',
|
base: '/blog',
|
||||||
});
|
});
|
||||||
await fixtureWithBase.build();
|
await fixtureWithBase.build();
|
||||||
|
@ -530,6 +568,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
// Remove cache directory
|
// Remove cache directory
|
||||||
removeDir(new URL('./fixtures/core-image-ssg/node_modules/.astro', import.meta.url));
|
removeDir(new URL('./fixtures/core-image-ssg/node_modules/.astro', import.meta.url));
|
||||||
|
@ -693,6 +734,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
devServer = await fixture.startDevServer();
|
devServer = await fixture.startDevServer();
|
||||||
});
|
});
|
||||||
|
@ -717,6 +761,9 @@ describe('astro:image', () => {
|
||||||
experimental: {
|
experimental: {
|
||||||
assets: true,
|
assets: true,
|
||||||
},
|
},
|
||||||
|
image: {
|
||||||
|
service: testImageService(),
|
||||||
|
},
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
});
|
});
|
||||||
|
@ -746,50 +793,4 @@ describe('astro:image', () => {
|
||||||
expect(imgData).to.be.an.instanceOf(Buffer);
|
expect(imgData).to.be.an.instanceOf(Buffer);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('custom service', () => {
|
|
||||||
/** @type {import('./test-utils').DevServer} */
|
|
||||||
let devServer;
|
|
||||||
before(async () => {
|
|
||||||
fixture = await loadFixture({
|
|
||||||
root: './fixtures/core-image/',
|
|
||||||
experimental: {
|
|
||||||
assets: true,
|
|
||||||
},
|
|
||||||
image: {
|
|
||||||
service: {
|
|
||||||
entrypoint: fileURLToPath(
|
|
||||||
new URL('./fixtures/core-image/service.mjs', import.meta.url)
|
|
||||||
),
|
|
||||||
config: { foo: 'bar' },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
devServer = await fixture.startDevServer();
|
|
||||||
});
|
|
||||||
|
|
||||||
it('custom service implements getHTMLAttributes', async () => {
|
|
||||||
const response = await fixture.fetch('/');
|
|
||||||
const html = await response.text();
|
|
||||||
|
|
||||||
const $ = cheerio.load(html);
|
|
||||||
expect($('#local img').attr('data-service')).to.equal('my-custom-service');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('custom service works in Markdown', async () => {
|
|
||||||
const response = await fixture.fetch('/post');
|
|
||||||
const html = await response.text();
|
|
||||||
|
|
||||||
const $ = cheerio.load(html);
|
|
||||||
expect($('img').attr('data-service')).to.equal('my-custom-service');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('gets service config', async () => {
|
|
||||||
const response = await fixture.fetch('/');
|
|
||||||
const html = await response.text();
|
|
||||||
|
|
||||||
const $ = cheerio.load(html);
|
|
||||||
expect($('#local img').attr('data-service-config')).to.equal('bar');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
|
@ -1,23 +0,0 @@
|
||||||
import squoosh from 'astro/assets/services/squoosh';
|
|
||||||
|
|
||||||
const service = {
|
|
||||||
validateOptions(options) {
|
|
||||||
return squoosh.validateOptions(options);
|
|
||||||
},
|
|
||||||
getURL(options) {
|
|
||||||
return squoosh.getURL(options);
|
|
||||||
},
|
|
||||||
getHTMLAttributes(options, serviceConfig) {
|
|
||||||
options['data-service'] = 'my-custom-service';
|
|
||||||
options['data-service-config'] = serviceConfig.foo;
|
|
||||||
return squoosh.getHTMLAttributes(options);
|
|
||||||
},
|
|
||||||
parseURL(url) {
|
|
||||||
return squoosh.parseURL(url);
|
|
||||||
},
|
|
||||||
transform(buffer, options) {
|
|
||||||
return squoosh.transform(buffer, options);
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
export default service;
|
|
|
@ -4,6 +4,6 @@ import { One as OneWrapper } from '../components/One';
|
||||||
<html>
|
<html>
|
||||||
<head><title>Testing</title></head>
|
<head><title>Testing</title></head>
|
||||||
<body>
|
<body>
|
||||||
<OneWrapper client:load />
|
<OneWrapper />
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -33,7 +33,7 @@ describe('HTML minification', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
devServer.stop();
|
await devServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should emit compressed HTML in the emitted file', async () => {
|
it('should emit compressed HTML in the emitted file', async () => {
|
||||||
|
|
|
@ -56,7 +56,7 @@ describe('Prerender', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
devServer.stop();
|
await devServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls prerender getStaticPaths once', async () => {
|
it('only calls prerender getStaticPaths once', async () => {
|
||||||
|
@ -188,7 +188,7 @@ describe('Prerender', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
after(async () => {
|
after(async () => {
|
||||||
devServer.stop();
|
await devServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls hybrid getStaticPaths once', async () => {
|
it('only calls hybrid getStaticPaths once', async () => {
|
||||||
|
|
31
packages/astro/test/test-image-service.js
Normal file
31
packages/astro/test/test-image-service.js
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
import { baseService } from '../dist/assets/services/service.js';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* stub image service that returns images as-is without optimization
|
||||||
|
* @param {{ foo?: string }} [config]
|
||||||
|
*/
|
||||||
|
export function testImageService(config = {}) {
|
||||||
|
return {
|
||||||
|
entrypoint: fileURLToPath(import.meta.url),
|
||||||
|
config,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @type {import("../dist/@types/astro").LocalImageService} */
|
||||||
|
export default {
|
||||||
|
...baseService,
|
||||||
|
getHTMLAttributes(options, serviceConfig) {
|
||||||
|
options['data-service'] = 'my-custom-service';
|
||||||
|
if (serviceConfig.foo) {
|
||||||
|
options['data-service-config'] = serviceConfig.foo;
|
||||||
|
}
|
||||||
|
return baseService.getHTMLAttributes(options);
|
||||||
|
},
|
||||||
|
async transform(buffer, transform) {
|
||||||
|
return {
|
||||||
|
data: buffer,
|
||||||
|
format: transform.format,
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
21
packages/astro/test/units/logger/locale.test.js
Normal file
21
packages/astro/test/units/logger/locale.test.js
Normal file
|
@ -0,0 +1,21 @@
|
||||||
|
import { expect } from 'chai';
|
||||||
|
|
||||||
|
const LOCALES = ['en_US', 'sv_SE', 'es_419.UTF-8', 'es_ES@euro', 'C'];
|
||||||
|
|
||||||
|
describe('logger - dateTimeFormat', () => {
|
||||||
|
const originalLang = process.env.LANG;
|
||||||
|
|
||||||
|
after(() => {
|
||||||
|
process.env.LANG = originalLang;
|
||||||
|
});
|
||||||
|
|
||||||
|
LOCALES.forEach((locale, i) => {
|
||||||
|
it(`works with process.env.LANG="${locale}"`, async () => {
|
||||||
|
process.env.LANG = locale;
|
||||||
|
const { dateTimeFormat } = await import('../../../dist/core/logger/core.js?cachebust=' + i);
|
||||||
|
expect(() => {
|
||||||
|
dateTimeFormat.format(new Date());
|
||||||
|
}).not.to.throw();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
|
@ -20,7 +20,8 @@ describe('<Code />', () => {
|
||||||
|
|
||||||
it('uses the bundles themes for built-in themes', async () => {
|
it('uses the bundles themes for built-in themes', async () => {
|
||||||
const { resolveHighlighterOptions } = mod;
|
const { resolveHighlighterOptions } = mod;
|
||||||
const opts = await resolveHighlighterOptions({ theme: 'css-variables' });
|
// NOTE: pass empty `langs` to prevent Shiki from loading all langs by default, which slows down the test
|
||||||
|
const opts = await resolveHighlighterOptions({ theme: 'css-variables', langs: [] });
|
||||||
const themes = opts.themes;
|
const themes = opts.themes;
|
||||||
|
|
||||||
expect(themes).to.have.a.lengthOf(1);
|
expect(themes).to.have.a.lengthOf(1);
|
||||||
|
@ -29,7 +30,8 @@ describe('<Code />', () => {
|
||||||
|
|
||||||
it('uses the string theme name for custom themes', async () => {
|
it('uses the string theme name for custom themes', async () => {
|
||||||
const { resolveHighlighterOptions } = mod;
|
const { resolveHighlighterOptions } = mod;
|
||||||
const opts = await resolveHighlighterOptions({ theme: 'some-custom-theme' });
|
// NOTE: pass empty `langs` to prevent Shiki from loading all langs by default, which slows down the test
|
||||||
|
const opts = await resolveHighlighterOptions({ theme: 'some-custom-theme', langs: [] });
|
||||||
const themes = opts.themes;
|
const themes = opts.themes;
|
||||||
|
|
||||||
expect(themes).to.have.a.lengthOf(1);
|
expect(themes).to.have.a.lengthOf(1);
|
||||||
|
|
Loading…
Add table
Reference in a new issue