summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--packages/astro/package.json7
-rw-r--r--packages/astro/test/astro-basic.test.js315
-rw-r--r--packages/astro/test/cli.test.js1
-rw-r--r--packages/astro/test/i18n-routing.nodetest.js (renamed from packages/astro/test/i18n-routing.test.js)611
4 files changed, 470 insertions, 464 deletions
diff --git a/packages/astro/package.json b/packages/astro/package.json
index f0b60bc44..5222a540c 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -107,11 +107,12 @@
"dev": "astro-scripts dev --copy-wasm --prebuild \"src/runtime/server/astro-island.ts\" --prebuild \"src/runtime/client/{idle,load,media,only,visible}.ts\" \"src/**/*.{ts,js}\"",
"postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
"test:unit": "mocha --exit --timeout 30000 ./test/units/**/*.test.js",
- "test:unit:match": "mocha --exit --timeout 30000 ./test/units/**/*.test.js -g",
- "test": "pnpm run test:unit && mocha --exit --timeout 30000 --ignore **/lit-element.test.js && mocha --timeout 30000 **/lit-element.test.js",
+ "test:unit:match": "mocha --exit --timeout 30000 ./test/units/**/*.test.js -g --ignore **/*.nodetest.js",
+ "test": "pnpm run test:node && pnpm run test:unit && mocha --exit --timeout 30000 --ignore **/*.nodetest.js --ignore **/lit-element.test.js && mocha --timeout 30000 **/lit-element.test.js --ignore **/*.nodetest.js",
"test:match": "mocha --timeout 30000 -g",
"test:e2e": "playwright test",
- "test:e2e:match": "playwright test -g"
+ "test:e2e:match": "playwright test -g",
+ "test:node": "astro-scripts test \"test/**/*.nodetest.js\""
},
"dependencies": {
"@astrojs/compiler": "^2.5.3",
diff --git a/packages/astro/test/astro-basic.test.js b/packages/astro/test/astro-basic.test.js
index 78c3a0ed5..6bd78c2d3 100644
--- a/packages/astro/test/astro-basic.test.js
+++ b/packages/astro/test/astro-basic.test.js
@@ -2,214 +2,211 @@ import { expect } from 'chai';
import * as cheerio from 'cheerio';
import { loadFixture } from './test-utils.js';
-describe('Astro basics', () => {
+describe('Astro basic build', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ let previewServer;
+
before(async () => {
fixture = await loadFixture({
root: './fixtures/astro-basic/',
});
+ await fixture.build();
+ previewServer = await fixture.preview();
});
- describe('build', () => {
- let previewServer;
-
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/astro-basic/',
- });
- await fixture.build();
- previewServer = await fixture.preview();
- });
+ // important: close preview server (free up port and connection)
+ after(async () => {
+ await previewServer.stop();
+ });
- // important: close preview server (free up port and connection)
- after(async () => {
- await previewServer.stop();
- });
+ it('Can load page', async () => {
+ const html = await fixture.readFile(`/index.html`);
+ const $ = cheerio.load(html);
- it('Can load page', async () => {
- const html = await fixture.readFile(`/index.html`);
- const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('Hello world!');
+ });
- expect($('h1').text()).to.equal('Hello world!');
- });
+ it('Correctly serializes boolean attributes', async () => {
+ const html = await fixture.readFile('/index.html');
+ const $ = cheerio.load(html);
- it('Correctly serializes boolean attributes', async () => {
- const html = await fixture.readFile('/index.html');
- const $ = cheerio.load(html);
+ expect($('h1').attr('data-something')).to.equal('');
+ expect($('h2').attr('not-data-ok')).to.equal('');
+ });
- expect($('h1').attr('data-something')).to.equal('');
- expect($('h2').attr('not-data-ok')).to.equal('');
- });
+ it('Selector with an empty body', async () => {
+ const html = await fixture.readFile('/empty-class/index.html');
+ const $ = cheerio.load(html);
- it('Selector with an empty body', async () => {
- const html = await fixture.readFile('/empty-class/index.html');
- const $ = cheerio.load(html);
+ expect($('.author')).to.have.lengthOf(1);
+ });
- expect($('.author')).to.have.lengthOf(1);
- });
+ it('Allows forward-slashes in mustache tags (#407)', async () => {
+ const html = await fixture.readFile('/forward-slash/index.html');
+ const $ = cheerio.load(html);
- it('Allows forward-slashes in mustache tags (#407)', async () => {
- const html = await fixture.readFile('/forward-slash/index.html');
- const $ = cheerio.load(html);
+ expect($('a[href="/post/one"]')).to.have.lengthOf(1);
+ expect($('a[href="/post/two"]')).to.have.lengthOf(1);
+ expect($('a[href="/post/three"]')).to.have.lengthOf(1);
+ });
- expect($('a[href="/post/one"]')).to.have.lengthOf(1);
- expect($('a[href="/post/two"]')).to.have.lengthOf(1);
- expect($('a[href="/post/three"]')).to.have.lengthOf(1);
- });
+ it('Allows spread attributes (#521)', async () => {
+ const html = await fixture.readFile('/spread/index.html');
+ const $ = cheerio.load(html);
- it('Allows spread attributes (#521)', async () => {
- const html = await fixture.readFile('/spread/index.html');
- const $ = cheerio.load(html);
+ expect($('#spread-leading')).to.have.lengthOf(1);
+ expect($('#spread-leading').attr('a')).to.equal('0');
+ expect($('#spread-leading').attr('b')).to.equal('1');
+ expect($('#spread-leading').attr('c')).to.equal('2');
- expect($('#spread-leading')).to.have.lengthOf(1);
- expect($('#spread-leading').attr('a')).to.equal('0');
- expect($('#spread-leading').attr('b')).to.equal('1');
- expect($('#spread-leading').attr('c')).to.equal('2');
+ expect($('#spread-trailing')).to.have.lengthOf(1);
+ expect($('#spread-trailing').attr('a')).to.equal('0');
+ expect($('#spread-trailing').attr('b')).to.equal('1');
+ expect($('#spread-trailing').attr('c')).to.equal('2');
+ });
- expect($('#spread-trailing')).to.have.lengthOf(1);
- expect($('#spread-trailing').attr('a')).to.equal('0');
- expect($('#spread-trailing').attr('b')).to.equal('1');
- expect($('#spread-trailing').attr('c')).to.equal('2');
- });
+ it('Allows spread attributes with TypeScript (#521)', async () => {
+ const html = await fixture.readFile('/spread/index.html');
+ const $ = cheerio.load(html);
- it('Allows spread attributes with TypeScript (#521)', async () => {
- const html = await fixture.readFile('/spread/index.html');
- const $ = cheerio.load(html);
+ expect($('#spread-ts')).to.have.lengthOf(1);
+ expect($('#spread-ts').attr('a')).to.equal('0');
+ expect($('#spread-ts').attr('b')).to.equal('1');
+ expect($('#spread-ts').attr('c')).to.equal('2');
+ });
- expect($('#spread-ts')).to.have.lengthOf(1);
- expect($('#spread-ts').attr('a')).to.equal('0');
- expect($('#spread-ts').attr('b')).to.equal('1');
- expect($('#spread-ts').attr('c')).to.equal('2');
- });
+ it('Allows scoped classes with spread', async () => {
+ const html = await fixture.readFile('/spread-scope/index.html');
+ const $ = cheerio.load(html);
- it('Allows scoped classes with spread', async () => {
- const html = await fixture.readFile('/spread-scope/index.html');
- const $ = cheerio.load(html);
+ expect($('#spread-plain')).to.have.lengthOf(1);
+ expect($('#spread-plain').attr('class')).to.match(/astro-.*/);
- expect($('#spread-plain')).to.have.lengthOf(1);
- expect($('#spread-plain').attr('class')).to.match(/astro-.*/);
+ expect($('#spread-class')).to.have.lengthOf(1);
+ expect($('#spread-class').attr('class')).to.match(/astro-.*/);
- expect($('#spread-class')).to.have.lengthOf(1);
- expect($('#spread-class').attr('class')).to.match(/astro-.*/);
+ expect($('#spread-class-list')).to.have.lengthOf(1);
+ expect($('#spread-class-list').attr('class')).to.match(/astro-.*/);
+ });
- expect($('#spread-class-list')).to.have.lengthOf(1);
- expect($('#spread-class-list').attr('class')).to.match(/astro-.*/);
- });
+ it('Allows using the Fragment element to be used', async () => {
+ const html = await fixture.readFile('/fragment/index.html');
+ const $ = cheerio.load(html);
- it('Allows using the Fragment element to be used', async () => {
- const html = await fixture.readFile('/fragment/index.html');
- const $ = cheerio.load(html);
+ // will be 1 if element rendered correctly
+ expect($('#one')).to.have.lengthOf(1);
+ });
- // will be 1 if element rendered correctly
- expect($('#one')).to.have.lengthOf(1);
- });
+ it('supports special chars in filename', async () => {
+ // will have already erred by now, but add test anyway
+ expect(await fixture.readFile('/special-“characters” -in-file/index.html')).to.be.ok;
+ });
- it('supports special chars in filename', async () => {
- // will have already erred by now, but add test anyway
- expect(await fixture.readFile('/special-“characters” -in-file/index.html')).to.be.ok;
- });
+ it('renders the components top-down', async () => {
+ const html = await fixture.readFile('/order/index.html');
+ const $ = cheerio.load(html);
+ expect($('#rendered-order').text()).to.eq('Rendered order: A, B');
+ });
- it('renders the components top-down', async () => {
- const html = await fixture.readFile('/order/index.html');
- const $ = cheerio.load(html);
- expect($('#rendered-order').text()).to.eq('Rendered order: A, B');
- });
+ it('renders markdown in utf-8 by default', async () => {
+ const html = await fixture.readFile('/chinese-encoding-md/index.html');
+ const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('我的第一篇博客文章');
+ });
- it('renders markdown in utf-8 by default', async () => {
- const html = await fixture.readFile('/chinese-encoding-md/index.html');
- const $ = cheerio.load(html);
- expect($('h1').text()).to.equal('我的第一篇博客文章');
- });
+ it('renders MDX in utf-8 by default', async () => {
+ const html = await fixture.readFile('/chinese-encoding-mdx/index.html');
+ const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('我的第一篇博客文章');
+ });
- it('renders MDX in utf-8 by default', async () => {
- const html = await fixture.readFile('/chinese-encoding-mdx/index.html');
- const $ = cheerio.load(html);
- expect($('h1').text()).to.equal('我的第一篇博客文章');
- });
+ it('Supports void elements whose name is a string (#2062)', async () => {
+ const html = await fixture.readFile('/input/index.html');
+ const $ = cheerio.load(html);
- it('Supports void elements whose name is a string (#2062)', async () => {
- const html = await fixture.readFile('/input/index.html');
- const $ = cheerio.load(html);
+ // <Input />
+ expect($('body > :nth-child(1)').prop('outerHTML')).to.equal('<input>');
- // <Input />
- expect($('body > :nth-child(1)').prop('outerHTML')).to.equal('<input>');
+ // <Input type="password" />
+ expect($('body > :nth-child(2)').prop('outerHTML')).to.equal('<input type="password">');
- // <Input type="password" />
- expect($('body > :nth-child(2)').prop('outerHTML')).to.equal('<input type="password">');
+ // <Input type="text" />
+ expect($('body > :nth-child(3)').prop('outerHTML')).to.equal('<input type="text">');
- // <Input type="text" />
- expect($('body > :nth-child(3)').prop('outerHTML')).to.equal('<input type="text">');
+ // <Input type="select"><option>option</option></Input>
+ expect($('body > :nth-child(4)').prop('outerHTML')).to.equal(
+ '<select><option>option</option></select>'
+ );
- // <Input type="select"><option>option</option></Input>
- expect($('body > :nth-child(4)').prop('outerHTML')).to.equal(
- '<select><option>option</option></select>'
- );
+ // <Input type="textarea">textarea</Input>
+ expect($('body > :nth-child(5)').prop('outerHTML')).to.equal('<textarea>textarea</textarea>');
+ });
- // <Input type="textarea">textarea</Input>
- expect($('body > :nth-child(5)').prop('outerHTML')).to.equal('<textarea>textarea</textarea>');
- });
+ it('Generates pages that end with .mjs', async () => {
+ const content1 = await fixture.readFile('/get-static-paths-with-mjs/example.mjs');
+ expect(content1).to.be.ok;
+ const content2 = await fixture.readFile('/get-static-paths-with-mjs/example.js');
+ expect(content2).to.be.ok;
+ });
- it('Generates pages that end with .mjs', async () => {
- const content1 = await fixture.readFile('/get-static-paths-with-mjs/example.mjs');
- expect(content1).to.be.ok;
- const content2 = await fixture.readFile('/get-static-paths-with-mjs/example.js');
- expect(content2).to.be.ok;
- });
+ it('allows file:// urls as module specifiers', async () => {
+ const html = await fixture.readFile('/fileurl/index.html');
+ const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('WORKS');
+ });
- it('allows file:// urls as module specifiers', async () => {
- const html = await fixture.readFile('/fileurl/index.html');
- const $ = cheerio.load(html);
- expect($('h1').text()).to.equal('WORKS');
+ describe('preview', () => {
+ it('returns 200 for valid URLs', async () => {
+ const result = await fixture.fetch('/');
+ expect(result.status).to.equal(200);
});
- describe('preview', () => {
- it('returns 200 for valid URLs', async () => {
- const result = await fixture.fetch('/');
- expect(result.status).to.equal(200);
- });
-
- it('returns 404 for invalid URLs', async () => {
- const result = await fixture.fetch('/bad-url');
- expect(result.status).to.equal(404);
- });
+ it('returns 404 for invalid URLs', async () => {
+ const result = await fixture.fetch('/bad-url');
+ expect(result.status).to.equal(404);
});
});
+});
- describe('development', () => {
- /** @type {import('./test-utils').DevServer} */
- let devServer;
+describe('Astro basic development', () => {
+ /** @type {import('./test-utils').DevServer} */
+ let devServer;
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
- before(async () => {
- devServer = await fixture.startDevServer();
- });
- after(async () => {
- await devServer.stop();
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/astro-basic/',
});
+ devServer = await fixture.startDevServer();
+ });
+ after(async () => {
+ await devServer.stop();
+ });
- it('Renders markdown in utf-8 by default', async () => {
- const res = await fixture.fetch('/chinese-encoding-md');
- expect(res.status).to.equal(200);
- const html = await res.text();
- const $ = cheerio.load(html);
- expect($('h1').text()).to.equal('我的第一篇博客文章');
- const isUtf8 =
- res.headers.get('content-type').includes('charset=utf-8') ||
- html.includes('<meta charset="utf-8">');
- expect(isUtf8).to.be.true;
- });
+ it('Renders markdown in utf-8 by default', async () => {
+ const res = await fixture.fetch('/chinese-encoding-md');
+ expect(res.status).to.equal(200);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('我的第一篇博客文章');
+ const isUtf8 =
+ res.headers.get('content-type').includes('charset=utf-8') ||
+ html.includes('<meta charset="utf-8">');
+ expect(isUtf8).to.be.true;
+ });
- it('Renders MDX in utf-8 by default', async () => {
- const res = await fixture.fetch('/chinese-encoding-mdx');
- expect(res.status).to.equal(200);
- const html = await res.text();
- const $ = cheerio.load(html);
- expect($('h1').text()).to.equal('我的第一篇博客文章');
- const isUtf8 =
- res.headers.get('content-type').includes('charset=utf-8') ||
- html.includes('<meta charset="utf-8">');
- expect(isUtf8).to.be.true;
- });
+ it('Renders MDX in utf-8 by default', async () => {
+ const res = await fixture.fetch('/chinese-encoding-mdx');
+ expect(res.status).to.equal(200);
+ const html = await res.text();
+ const $ = cheerio.load(html);
+ expect($('h1').text()).to.equal('我的第一篇博客文章');
+ const isUtf8 =
+ res.headers.get('content-type').includes('charset=utf-8') ||
+ html.includes('<meta charset="utf-8">');
+ expect(isUtf8).to.be.true;
});
});
diff --git a/packages/astro/test/cli.test.js b/packages/astro/test/cli.test.js
index b276e74a4..8fb375fe9 100644
--- a/packages/astro/test/cli.test.js
+++ b/packages/astro/test/cli.test.js
@@ -105,7 +105,6 @@ describe('astro cli', () => {
const { messages } = await parseCliDevStart(proc);
const index = messages[0].includes('[vite]') ? 1 : 0;
-
expect(messages[index]).to.contain('astro');
expect(messages[index]).to.contain(pkgVersion);
expect(messages[index]).to.contain('ready in');
diff --git a/packages/astro/test/i18n-routing.test.js b/packages/astro/test/i18n-routing.nodetest.js
index da22f0311..1ef99e838 100644
--- a/packages/astro/test/i18n-routing.test.js
+++ b/packages/astro/test/i18n-routing.nodetest.js
@@ -1,7 +1,8 @@
-import { expect } from 'chai';
import * as cheerio from 'cheerio';
import testAdapter from './test-adapter.js';
import { loadFixture } from './test-utils.js';
+import { describe, it, before, after } from 'node:test';
+import * as assert from 'node:assert/strict';
describe('astro:i18n virtual module', () => {
/** @type {import('./test-utils').Fixture} */
@@ -22,14 +23,14 @@ describe('astro:i18n virtual module', () => {
it('correctly imports the functions', async () => {
const response = await fixture.fetch('/virtual-module');
- expect(response.status).to.equal(200);
+ assert.equal(response.status, 200);
const text = await response.text();
- expect(text).includes("Virtual module doesn't break");
- expect(text).includes('About: /pt/about');
- expect(text).includes('About spanish: /spanish/about');
- expect(text).includes('Spain path: spanish');
- expect(text).includes('Preferred path: es');
- expect(text).includes('About it: /it/about');
+ assert.equal(text.includes("Virtual module doesn't break"), true);
+ assert.equal(text.includes('About: /pt/about'), true);
+ assert.equal(text.includes('About spanish: /spanish/about'), true);
+ assert.equal(text.includes('Spain path: spanish'), true);
+ assert.equal(text.includes('Preferred path: es'), true);
+ assert.equal(text.includes('About it: /it/about'), true);
});
describe('absolute URLs', () => {
@@ -47,14 +48,14 @@ describe('astro:i18n virtual module', () => {
it('correctly renders the absolute URL', async () => {
let request = new Request('http://example.com/');
let response = await app.render(request);
- expect(response.status).to.equal(200);
+ assert.equal(response.status, 200);
let html = await response.text();
let $ = cheerio.load(html);
- expect($('body').text()).includes("Virtual module doesn't break");
- expect($('body').text()).includes('Absolute URL pt: https://example.pt/about');
- expect($('body').text()).includes('Absolute URL it: http://it.example.com/');
+ assert.equal($('body').text().includes("Virtual module doesn't break"), true);
+ assert.equal($('body').text().includes('Absolute URL pt: https://example.pt/about'), true);
+ assert.equal($('body').text().includes('Absolute URL it: http://it.example.com/'), true);
});
});
});
@@ -78,8 +79,8 @@ describe('[DEV] i18n routing', () => {
it('renders the page', async () => {
const response = await fixture.fetch('/endurance');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Endurance');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Endurance'), true);
});
});
@@ -102,42 +103,42 @@ describe('[DEV] i18n routing', () => {
it('should render the en locale', async () => {
const response = await fixture.fetch('/en/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
const response2 = await fixture.fetch('/en/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
const response = await fixture.fetch('/pt/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
const response2 = await fixture.fetch('/pt/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hola mundo');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hola mundo'), true);
});
it('should render localised page correctly when using path+codes', async () => {
const response = await fixture.fetch('/spanish/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
const response2 = await fixture.fetch('/spanish/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Lo siento');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
const response = await fixture.fetch('/it/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
const response = await fixture.fetch('/fr/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
@@ -160,42 +161,42 @@ describe('[DEV] i18n routing', () => {
it('should render the en locale', async () => {
const response = await fixture.fetch('/new-site/en/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Hello');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Hello'), true);
const response2 = await fixture.fetch('/new-site/en/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
const response = await fixture.fetch('/new-site/pt/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Hola');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Hola'), true);
const response2 = await fixture.fetch('/new-site/pt/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hola mundo');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hola mundo'), true);
});
it('should render localised page correctly when using path+codes', async () => {
const response = await fixture.fetch('/new-site/spanish/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
const response2 = await fixture.fetch('/new-site/spanish/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Lo siento');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
const response = await fixture.fetch('/new-site/it/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
const response = await fixture.fetch('/new-site/fr/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
@@ -234,89 +235,93 @@ describe('[DEV] i18n routing', () => {
it('should render the default locale without prefix', async () => {
const response = await fixture.fetch('/new-site/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
const response2 = await fixture.fetch('/new-site/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should return 404 when route contains the default locale', async () => {
const response = await fixture.fetch('/new-site/en/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
const response2 = await fixture.fetch('/new-site/en/blog/1');
- expect(response2.status).to.equal(404);
+ assert.equal(response2.status, 404);
});
it('should render localised page correctly', async () => {
const response = await fixture.fetch('/new-site/pt/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
const response2 = await fixture.fetch('/new-site/pt/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hola mundo');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hola mundo'), true);
});
it('should render localised page correctly when using path+codes', async () => {
const response = await fixture.fetch('/new-site/spanish/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
const response2 = await fixture.fetch('/new-site/spanish/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Lo siento');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Lo siento'), true);
});
it('should redirect to the english locale, which is the first fallback', async () => {
const response = await fixture.fetch('/new-site/it/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
const response = await fixture.fetch('/new-site/fr/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
+ });
- describe('when `build.format` is `directory`', () => {
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/i18n-routing-prefix-other-locales/',
- i18n: {
- defaultLocale: 'en',
- locales: [
- 'en',
- 'pt',
- 'it',
- {
- path: 'spanish',
- codes: ['es', 'es-AR'],
- },
- ],
- fallback: {
- it: 'en',
- spanish: 'en',
+ describe('i18n routing with routing strategy [prefix-other-locales], when `build.format` is `directory`', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+ /** @type {import('./test-utils').DevServer} */
+ let devServer;
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/i18n-routing-prefix-other-locales/',
+ i18n: {
+ defaultLocale: 'en',
+ locales: [
+ 'en',
+ 'pt',
+ 'it',
+ {
+ path: 'spanish',
+ codes: ['es', 'es-AR'],
},
+ ],
+ fallback: {
+ it: 'en',
+ spanish: 'en',
},
- build: {
- format: 'directory',
- },
- });
- devServer = await fixture.startDevServer();
+ },
+ build: {
+ format: 'directory',
+ },
});
+ devServer = await fixture.startDevServer();
+ });
- after(async () => {
- await devServer.stop();
- });
+ after(async () => {
+ await devServer.stop();
+ });
- it('should redirect to the english locale with trailing slash', async () => {
- const response = await fixture.fetch('/new-site/it/start/');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
- });
+ it('should redirect to the english locale with trailing slash', async () => {
+ const response = await fixture.fetch('/new-site/it/start/');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
});
@@ -345,8 +350,8 @@ describe('[DEV] i18n routing', () => {
it('should NOT redirect to the index of the default locale', async () => {
const response = await fixture.fetch('/new-site');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('I am index');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('I am index'), true);
});
});
@@ -369,78 +374,82 @@ describe('[DEV] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
const response = await fixture.fetch('/new-site');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Hello');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Hello'), true);
});
it('should not render the default locale without prefix', async () => {
const response = await fixture.fetch('/new-site/start');
- expect(response.status).to.equal(404);
- expect(await response.text()).not.includes('Start');
+ assert.equal(response.status, 404);
+ assert.equal((await response.text()).includes('Start'), false);
const response2 = await fixture.fetch('/new-site/blog/1');
- expect(response2.status).to.equal(404);
- expect(await response2.text()).not.includes('Hello world');
+ assert.equal(response2.status, 404);
+ assert.equal((await response2.text()).includes('Hello world'), false);
});
it('should render the default locale with prefix', async () => {
const response = await fixture.fetch('/new-site/en/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
const response2 = await fixture.fetch('/new-site/en/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
const response = await fixture.fetch('/new-site/pt/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
const response2 = await fixture.fetch('/new-site/pt/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hola mundo');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hola mundo'), true);
});
it('should render localised page correctly when using path+codes', async () => {
const response = await fixture.fetch('/new-site/spanish/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
const response2 = await fixture.fetch('/new-site/spanish/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Lo siento');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Lo siento'), true);
});
it('should not redirect to the english locale', async () => {
const response = await fixture.fetch('/new-site/it/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
const response = await fixture.fetch('/new-site/fr/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
+ });
- describe('[trailingSlash: always]', () => {
- before(async () => {
- fixture = await loadFixture({
- root: './fixtures/i18n-routing-prefix-always/',
- trailingSlash: 'always',
- });
- devServer = await fixture.startDevServer();
+ describe('[trailingSlash: always]', () => {
+ /** @type {import('./test-utils').Fixture} */
+ let fixture;
+ /** @type {import('./test-utils').DevServer} */
+ let devServer;
+ before(async () => {
+ fixture = await loadFixture({
+ root: './fixtures/i18n-routing-prefix-always/',
+ trailingSlash: 'always',
});
+ devServer = await fixture.startDevServer();
+ });
- after(async () => {
- await devServer.stop();
- });
+ after(async () => {
+ await devServer.stop();
+ });
- it('should redirect to the index of the default locale', async () => {
- const response = await fixture.fetch('/new-site/');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Hello');
- });
+ it('should redirect to the index of the default locale', async () => {
+ const response = await fixture.fetch('/new-site/');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Hello'), true);
});
});
@@ -482,43 +491,43 @@ describe('[DEV] i18n routing', () => {
it('should render the default locale without prefix', async () => {
const response = await fixture.fetch('/new-site/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
const response2 = await fixture.fetch('/new-site/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
const response = await fixture.fetch('/new-site/pt/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
const response2 = await fixture.fetch('/new-site/pt/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hola mundo');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hola mundo'), true);
});
it('should render localised page correctly when using path+codes', async () => {
const response = await fixture.fetch('/new-site/spanish/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
const response2 = await fixture.fetch('/new-site/spanish/blog/1');
- expect(response2.status).to.equal(200);
- expect(await response2.text()).includes('Hello world');
+ assert.equal(response2.status, 200);
+ assert.equal((await response2.text()).includes('Hello world'), true);
});
it('should redirect to the english locale, which is the first fallback', async () => {
const response = await fixture.fetch('/new-site/it/start');
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
const response = await fixture.fetch('/new-site/fr/start');
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
});
@@ -537,31 +546,31 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/en/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Start');
+ assert.equal($('body').text().includes('Start'), true);
html = await fixture.readFile('/en/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hello world');
+ assert.equal($('body').text().includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
let html = await fixture.readFile('/pt/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Oi essa e start');
+ assert.equal($('body').text().includes('Oi essa e start'), true);
html = await fixture.readFile('/pt/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hola mundo');
+ assert.equal($('body').text().includes('Hola mundo'), true);
});
it('should render localised page correctly when it has codes+path', async () => {
let html = await fixture.readFile('/spanish/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Espanol');
+ assert.equal($('body').text().includes('Espanol'), true);
html = await fixture.readFile('/spanish/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Lo siento');
+ assert.equal($('body').text().includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
@@ -601,31 +610,31 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/en/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Hello');
+ assert.equal($('body').text().includes('Hello'), true);
html = await fixture.readFile('/en/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hello world');
+ assert.equal($('body').text().includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
let html = await fixture.readFile('/pt/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Hola');
+ assert.equal($('body').text().includes('Hola'), true);
html = await fixture.readFile('/pt/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hola mundo');
+ assert.equal($('body').text().includes('Hola mundo'), true);
});
it('should render localised page correctly when it has codes+path', async () => {
let html = await fixture.readFile('/spanish/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Espanol');
+ assert.equal($('body').text().includes('Espanol'), true);
html = await fixture.readFile('/spanish/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Lo siento');
+ assert.equal($('body').text().includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
@@ -665,11 +674,11 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Start');
+ assert.equal($('body').text().includes('Start'), true);
html = await fixture.readFile('/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hello world');
+ assert.equal($('body').text().includes('Hello world'), true);
});
it('should return 404 when route contains the default locale', async () => {
@@ -686,21 +695,21 @@ describe('[SSG] i18n routing', () => {
it('should render localised page correctly', async () => {
let html = await fixture.readFile('/pt/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Oi essa e start');
+ assert.equal($('body').text().includes('Oi essa e start'), true);
html = await fixture.readFile('/pt/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hola mundo');
+ assert.equal($('body').text().includes('Hola mundo'), true);
});
it('should render localised page correctly when it has codes+path', async () => {
let html = await fixture.readFile('/spanish/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Espanol');
+ assert.equal($('body').text().includes('Espanol'), true);
html = await fixture.readFile('/spanish/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Lo siento');
+ assert.equal($('body').text().includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
@@ -746,7 +755,7 @@ describe('[SSG] i18n routing', () => {
it('should NOT redirect to the index of the default locale', async () => {
const html = await fixture.readFile('/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('I am index');
+ assert.equal($('body').text().includes('I am index'), true);
});
});
@@ -763,39 +772,39 @@ describe('[SSG] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
const html = await fixture.readFile('/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en'), true);
});
it('should render the en locale', async () => {
let html = await fixture.readFile('/en/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Start');
+ assert.equal($('body').text().includes('Start'), true);
html = await fixture.readFile('/en/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hello world');
+ assert.equal($('body').text().includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
let html = await fixture.readFile('/pt/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Oi essa e start');
+ assert.equal($('body').text().includes('Oi essa e start'), true);
html = await fixture.readFile('/pt/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hola mundo');
+ assert.equal($('body').text().includes('Hola mundo'), true);
});
it('should render localised page correctly when it has codes+path', async () => {
let html = await fixture.readFile('/spanish/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Espanol');
+ assert.equal($('body').text().includes('Espanol'), true);
html = await fixture.readFile('/spanish/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Lo siento');
+ assert.equal($('body').text().includes('Lo siento'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
@@ -830,8 +839,8 @@ describe('[SSG] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
const html = await fixture.readFile('/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en'), true);
});
});
@@ -848,9 +857,9 @@ describe('[SSG] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
const html = await fixture.readFile('/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en/');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en/'), true);
});
});
});
@@ -885,39 +894,39 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Start');
+ assert.equal($('body').text().includes('Start'), true);
html = await fixture.readFile('/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hello world');
+ assert.equal($('body').text().includes('Hello world'), true);
});
it('should render localised page correctly', async () => {
let html = await fixture.readFile('/pt/start/index.html');
let $ = cheerio.load(html);
- expect($('body').text()).includes('Oi essa e start: pt');
+ assert.equal($('body').text().includes('Oi essa e start: pt'), true);
html = await fixture.readFile('/pt/blog/1/index.html');
$ = cheerio.load(html);
- expect($('body').text()).includes('Hola mundo');
+ assert.equal($('body').text().includes('Hola mundo'), true);
});
it('should redirect to the english locale correctly when it has codes+path', async () => {
let html = await fixture.readFile('/spanish/start/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/start');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/start'), true);
html = await fixture.readFile('/spanish/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site'), true);
});
it('should redirect to the english locale, which is the first fallback', async () => {
let html = await fixture.readFile('/it/start/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/start');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/start'), true);
html = await fixture.readFile('/it/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site'), true);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
@@ -934,7 +943,7 @@ describe('[SSG] i18n routing', () => {
it('should render the page with client scripts', async () => {
let html = await fixture.readFile('/index.html');
let $ = cheerio.load(html);
- expect($('script').text()).includes('console.log("this is a script")');
+ assert.equal($('script').text().includes('console.log("this is a script")'), true);
});
});
@@ -961,11 +970,11 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/it/start/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en/start');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en/start'), true);
html = await fixture.readFile('/it/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en'), true);
});
});
@@ -992,8 +1001,8 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('Redirecting to: /en');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('Redirecting to: /en'), true);
});
});
@@ -1024,8 +1033,8 @@ describe('[SSG] i18n routing', () => {
it('should render the en locale', async () => {
let html = await fixture.readFile('/it/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('Redirecting to: /new-site/');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('Redirecting to: /new-site/'), true);
});
});
@@ -1042,7 +1051,7 @@ describe('[SSG] i18n routing', () => {
it('renders the page', async () => {
const html = await fixture.readFile('/endurance/index.html');
- expect(html).includes('Endurance');
+ assert.equal(html.includes('Endurance'), true);
});
});
@@ -1060,27 +1069,27 @@ describe('[SSG] i18n routing', () => {
it('should return the default locale', async () => {
const html = await fixture.readFile('/current-locale/index.html');
- expect(html).includes('Current Locale: en');
+ assert.equal(html.includes('Current Locale: en'), true);
});
it('should return the default locale when rendering a route with spread operator', async () => {
const html = await fixture.readFile('/blog/es/index.html');
- expect(html).includes('Current Locale: es');
+ assert.equal(html.includes('Current Locale: es'), true);
});
it('should return the default locale of the current URL', async () => {
const html = await fixture.readFile('/pt/start/index.html');
- expect(html).includes('Current Locale: pt');
+ assert.equal(html.includes('Current Locale: pt'), true);
});
it('should return the default locale when a route is dynamic', async () => {
const html = await fixture.readFile('/dynamic/lorem/index.html');
- expect(html).includes('Current Locale: en');
+ assert.equal(html.includes('Current Locale: en'), true);
});
it('should returns the correct locale when requesting a locale via path', async () => {
const html = await fixture.readFile('/spanish/index.html');
- expect(html).includes('Current Locale: es');
+ assert.equal(html.includes('Current Locale: es'), true);
});
});
@@ -1097,12 +1106,12 @@ describe('[SSG] i18n routing', () => {
it('should return the locale of the current URL (en)', async () => {
const html = await fixture.readFile('/en/start/index.html');
- expect(html).includes('Current Locale: en');
+ assert.equal(html.includes('Current Locale: en'), true);
});
it('should return the locale of the current URL (pt)', async () => {
const html = await fixture.readFile('/pt/start/index.html');
- expect(html).includes('Current Locale: pt');
+ assert.equal(html.includes('Current Locale: pt'), true);
});
});
});
@@ -1127,8 +1136,8 @@ describe('[SSR] i18n routing', () => {
it('renders the page', async () => {
let request = new Request('http://example.com/endurance');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Endurance');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Endurance'), true);
});
});
@@ -1149,41 +1158,41 @@ describe('[SSR] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
let request = new Request('http://example.com/new-site');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/en/');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/en/');
});
it('should render the en locale', async () => {
let request = new Request('http://example.com/en/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it('should render localised page correctly', async () => {
let request = new Request('http://example.com/pt/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
});
it('should render localised page correctly when locale has codes+path', async () => {
let request = new Request('http://example.com/spanish/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
let request = new Request('http://example.com/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
let request = new Request('http://example.com/fr/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
@@ -1204,27 +1213,27 @@ describe('[SSR] i18n routing', () => {
it('should render the en locale', async () => {
let request = new Request('http://example.com/en/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it('should render localised page correctly', async () => {
let request = new Request('http://example.com/new-site/pt/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
let request = new Request('http://example.com/new-site/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
let request = new Request('http://example.com/new-site/fr/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
@@ -1245,40 +1254,40 @@ describe('[SSR] i18n routing', () => {
it('should render the en locale', async () => {
let request = new Request('http://example.com/new-site/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it('should return 404 if route contains the default locale', async () => {
let request = new Request('http://example.com/new-site/en/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it('should render localised page correctly', async () => {
let request = new Request('http://example.com/new-site/pt/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
});
it('should render localised page correctly when locale has codes+path', async () => {
let request = new Request('http://example.com/new-site/spanish/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
let request = new Request('http://example.com/new-site/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
let request = new Request('http://example.com/new-site/fr/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
});
@@ -1305,8 +1314,8 @@ describe('[SSR] i18n routing', () => {
it('should NOT redirect the index to the default locale', async () => {
let request = new Request('http://example.com/new-site');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('I am index');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('I am index'), true);
});
});
@@ -1327,41 +1336,41 @@ describe('[SSR] i18n routing', () => {
it('should redirect the index to the default locale', async () => {
let request = new Request('http://example.com/new-site');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/en/');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/en/');
});
it('should render the en locale', async () => {
let request = new Request('http://example.com/new-site/en/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it('should render localised page correctly', async () => {
let request = new Request('http://example.com/pt/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
});
it('should render localised page correctly when locale has codes+path', async () => {
let request = new Request('http://example.com/spanish/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Espanol');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Espanol'), true);
});
it("should NOT render the default locale if there isn't a fallback and the route is missing", async () => {
let request = new Request('http://example.com/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
let request = new Request('http://example.com/fr/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
describe('[trailingSlash: always]', () => {
@@ -1379,8 +1388,8 @@ describe('[SSR] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
let request = new Request('http://example.com/new-site/');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/en/');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/en/');
});
});
@@ -1401,8 +1410,8 @@ describe('[SSR] i18n routing', () => {
it('should redirect to the index of the default locale', async () => {
let request = new Request('http://example.com/new-site/');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/en/');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/en/');
});
});
});
@@ -1440,35 +1449,35 @@ describe('[SSR] i18n routing', () => {
it('should render the en locale', async () => {
let request = new Request('http://example.com/new-site/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Start'), true);
});
it('should render localised page correctly', async () => {
let request = new Request('http://example.com/new-site/pt/start');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start'), true);
});
it('should redirect to the english locale, which is the first fallback', async () => {
let request = new Request('http://example.com/new-site/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/start');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/start');
});
it('should redirect to the english locale when locale has codes+path', async () => {
let request = new Request('http://example.com/new-site/spanish/start');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/start');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/start');
});
it("should render a 404 because the route `fr` isn't included in the list of locales of the configuration", async () => {
let request = new Request('http://example.com/new-site/fr/start');
let response = await app.render(request);
- expect(response.status).to.equal(404);
+ assert.equal(response.status, 404);
});
describe('with routing strategy [pathname-prefix-always]', () => {
@@ -1495,8 +1504,8 @@ describe('[SSR] i18n routing', () => {
it('should redirect to the english locale, which is the first fallback', async () => {
let request = new Request('http://example.com/new-site/it/start');
let response = await app.render(request);
- expect(response.status).to.equal(302);
- expect(response.headers.get('location')).to.equal('/new-site/start');
+ assert.equal(response.status, 302);
+ assert.equal(response.headers.get('location'), '/new-site/start');
});
});
});
@@ -1522,8 +1531,8 @@ describe('[SSR] i18n routing', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Locale: none');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Locale: none'), true);
});
it('should render the locale pt', async () => {
@@ -1533,8 +1542,8 @@ describe('[SSR] i18n routing', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Locale: pt');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Locale: pt'), true);
});
it('should render empty locales', async () => {
@@ -1545,9 +1554,9 @@ describe('[SSR] i18n routing', () => {
});
let response = await app.render(request);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(text).includes('Locale: none');
- expect(text).includes('Locale list: empty');
+ assert.equal(response.status, 200);
+ assert.equal(text.includes('Locale: none'), true);
+ assert.equal(text.includes('Locale list: empty'), true);
});
it('should render none as preferred locale, but have a list of locales that correspond to the initial locales', async () => {
@@ -1558,9 +1567,9 @@ describe('[SSR] i18n routing', () => {
});
let response = await app.render(request);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(text).includes('Locale: none');
- expect(text).includes('Locale list: en, pt, it');
+ assert.equal(response.status, 200);
+ assert.equal(text.includes('Locale: none'), true);
+ assert.equal(text.includes('Locale list: en, pt, it'), true);
});
describe('in case the configured locales use underscores', () => {
@@ -1586,9 +1595,9 @@ describe('[SSR] i18n routing', () => {
});
let response = await app.render(request);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(text).includes('Locale: pt_BR');
- expect(text).includes('Locale list: pt_BR, en_AU');
+ assert.equal(response.status, 200);
+ assert.equal(text.includes('Locale: pt_BR'), true);
+ assert.equal(text.includes('Locale list: pt_BR, en_AU'), true);
});
});
@@ -1620,9 +1629,9 @@ describe('[SSR] i18n routing', () => {
});
let response = await app.render(request);
const text = await response.text();
- expect(response.status).to.equal(200);
- expect(text).includes('Locale: english');
- expect(text).includes('Locale list: english');
+ assert.equal(response.status, 200);
+ assert.equal(text.includes('Locale: english'), true);
+ assert.equal(text.includes('Locale list: english'), true);
});
});
});
@@ -1645,29 +1654,29 @@ describe('[SSR] i18n routing', () => {
it('should return the default locale', async () => {
let request = new Request('http://example.com/current-locale', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: en');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: en'), true);
});
it('should return the default locale when rendering a route with spread operator', async () => {
let request = new Request('http://example.com/blog/es', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: es');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: es'), true);
});
it('should return the default locale of the current URL', async () => {
let request = new Request('http://example.com/pt/start', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: pt');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: pt'), true);
});
it('should return the default locale when a route is dynamic', async () => {
let request = new Request('http://example.com/dynamic/lorem', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: en');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: en'), true);
});
});
@@ -1688,15 +1697,15 @@ describe('[SSR] i18n routing', () => {
it('should return the locale of the current URL (en)', async () => {
let request = new Request('http://example.com/en/start', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: en');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: en'), true);
});
it('should return the locale of the current URL (pt)', async () => {
let request = new Request('http://example.com/pt/start', {});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Current Locale: pt');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Current Locale: pt'), true);
});
});
});
@@ -1717,8 +1726,8 @@ describe('[SSR] i18n routing', () => {
it('and render the index page, which is static', async () => {
const html = await fixture.readFile('/client/index.html');
- expect(html).to.include('http-equiv="refresh');
- expect(html).to.include('url=/new-site/en');
+ assert.equal(html.includes('http-equiv="refresh'), true);
+ assert.equal(html.includes('url=/new-site/en'), true);
});
});
});
@@ -1744,8 +1753,8 @@ describe('i18n routing does not break assets and endpoints', () => {
const html = await fixture.readFile('/index.html');
const $ = cheerio.load(html);
const src = $('#local img').attr('src');
- expect(src.length).to.be.greaterThan(0);
- expect(src.startsWith('/blog')).to.be.true;
+ assert.equal(src.length > 0, true);
+ assert.equal(src.startsWith('/blog'), true);
});
});
@@ -1765,11 +1774,11 @@ describe('i18n routing does not break assets and endpoints', () => {
app = await fixture.loadTestAdapterApp();
});
- it('should return the expected data', async () => {
+ it('should return the assert.equaled data', async () => {
let request = new Request('http://example.com/new-site/test.json');
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('lorem');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('lorem'), true);
});
});
@@ -1796,8 +1805,8 @@ describe('i18n routing does not break assets and endpoints', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start\n');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start\n'), true);
});
it('should render the en locale when Host header is passed', async () => {
@@ -1808,8 +1817,8 @@ describe('i18n routing does not break assets and endpoints', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start\n');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start\n'), true);
});
it('should render the en locale when Host header is passed and it has the port', async () => {
@@ -1820,8 +1829,8 @@ describe('i18n routing does not break assets and endpoints', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start\n');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start\n'), true);
});
it('should render when the protocol header we fallback to the one of the host', async () => {
@@ -1831,8 +1840,8 @@ describe('i18n routing does not break assets and endpoints', () => {
},
});
let response = await app.render(request);
- expect(response.status).to.equal(200);
- expect(await response.text()).includes('Oi essa e start\n');
+ assert.equal(response.status, 200);
+ assert.equal((await response.text()).includes('Oi essa e start\n'), true);
});
});
});