diff options
author | 2024-02-16 01:58:17 +0800 | |
---|---|---|
committer | 2024-02-15 17:58:17 +0000 | |
commit | 7bdcfb750ae5e8a9e2a0ee68c7ac03b82215d08f (patch) | |
tree | 1eb8f301c428b8cdc3dbabadd48272ac8d4d7453 | |
parent | 4b62bfbe76cdf2442c315300388212a4d68ccf31 (diff) | |
download | astro-7bdcfb750ae5e8a9e2a0ee68c7ac03b82215d08f.tar.gz astro-7bdcfb750ae5e8a9e2a0ee68c7ac03b82215d08f.tar.zst astro-7bdcfb750ae5e8a9e2a0ee68c7ac03b82215d08f.zip |
chore: migrate several tests to `node:test` (#10133)
* chore: migrate test files whose names start with `a` to `node:test`
* update assertion
* chore: remove mocha script
---------
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com>
-rw-r--r-- | packages/astro/package.json | 2 | ||||
-rw-r--r-- | packages/astro/test/api-routes.nodetest.js (renamed from packages/astro/test/api-routes.test.js) | 7 | ||||
-rw-r--r-- | packages/astro/test/astro-client-only.nodetest.js (renamed from packages/astro/test/astro-client-only.test.js) | 29 | ||||
-rw-r--r-- | packages/astro/test/astro-component-code.nodetest.js (renamed from packages/astro/test/astro-component-code.test.js) | 83 | ||||
-rw-r--r-- | packages/astro/test/astro-cookies.nodetest.js (renamed from packages/astro/test/astro-cookies.test.js) | 49 | ||||
-rw-r--r-- | packages/astro/test/astro-css-bundling.nodetest.js (renamed from packages/astro/test/astro-css-bundling.test.js) | 19 | ||||
-rw-r--r-- | packages/astro/test/astro-dev-headers.nodetest.js (renamed from packages/astro/test/astro-dev-headers.test.js) | 11 | ||||
-rw-r--r-- | packages/astro/test/astro-directives.nodetest.js (renamed from packages/astro/test/astro-directives.test.js) | 63 | ||||
-rw-r--r-- | packages/astro/test/astro-doctype.nodetest.js (renamed from packages/astro/test/astro-doctype.test.js) | 24 | ||||
-rw-r--r-- | packages/astro/test/astro-dynamic.nodetest.js (renamed from packages/astro/test/astro-dynamic.test.js) | 19 | ||||
-rw-r--r-- | packages/astro/test/astro-envs.nodetest.js (renamed from packages/astro/test/astro-envs.test.js) | 31 | ||||
-rw-r--r-- | packages/astro/test/astro-expr.nodetest.js (renamed from packages/astro/test/astro-expr.test.js) | 58 | ||||
-rw-r--r-- | packages/astro/test/astro-fallback.nodetest.js (renamed from packages/astro/test/astro-fallback.test.js) | 5 | ||||
-rw-r--r-- | packages/astro/test/astro-get-static-paths.nodetest.js (renamed from packages/astro/test/astro-get-static-paths.test.js) | 36 | ||||
-rw-r--r-- | packages/astro/test/astro-global.nodetest.js (renamed from packages/astro/test/astro-global.test.js) | 50 | ||||
-rw-r--r-- | packages/astro/test/astro-object-style.nodetest.js (renamed from packages/astro/test/astro-object-style.test.js) | 19 | ||||
-rw-r--r-- | packages/astro/test/astro-pages.nodetest.js (renamed from packages/astro/test/astro-pages.test.js) | 15 | ||||
-rw-r--r-- | packages/astro/test/astro-partial-html.nodetest.js (renamed from packages/astro/test/astro-partial-html.test.js) | 13 | ||||
-rw-r--r-- | packages/astro/test/astro-preview-headers.nodetest.js (renamed from packages/astro/test/astro-preview-headers.test.js) | 11 | ||||
-rw-r--r-- | packages/astro/test/astro-scripts.nodetest.js (renamed from packages/astro/test/astro-scripts.test.js) | 48 | ||||
-rw-r--r-- | packages/astro/test/astro-slots-nested.nodetest.js (renamed from packages/astro/test/astro-slots-nested.test.js) | 29 | ||||
-rw-r--r-- | packages/astro/test/astro-sync.nodetest.js (renamed from packages/astro/test/astro-sync.test.js) | 37 |
22 files changed, 358 insertions, 300 deletions
diff --git a/packages/astro/package.json b/packages/astro/package.json index 6fe67b2e0..2399ed3e1 100644 --- a/packages/astro/package.json +++ b/packages/astro/package.json @@ -107,7 +107,7 @@ "build:ci": "pnpm run prebuild && astro-scripts build \"src/**/*.{ts,js}\" && pnpm run postbuild", "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": "pnpm run test:node && mocha ./test/*.test.js --exit --timeout 30000", + "test": "pnpm run test:node", "test:match": "mocha ./test/*.test.js --timeout 30000 -g", "test:e2e": "playwright test", "test:e2e:match": "playwright test -g", diff --git a/packages/astro/test/api-routes.test.js b/packages/astro/test/api-routes.nodetest.js index 278d2454e..4e2a5c7d0 100644 --- a/packages/astro/test/api-routes.test.js +++ b/packages/astro/test/api-routes.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('API routes', () => { @@ -13,8 +14,8 @@ describe('API routes', () => { describe('Binary data', () => { it('can be returned from a response', async () => { const dat = await fixture.readFile('/binary.dat', null); - expect(dat.length).to.equal(1); - expect(dat[0]).to.equal(0xff); + assert.equal(dat.length, 1); + assert.equal(dat[0], 0xff); }); }); }); diff --git a/packages/astro/test/astro-client-only.test.js b/packages/astro/test/astro-client-only.nodetest.js index 92b1beda4..88b762e73 100644 --- a/packages/astro/test/astro-client-only.test.js +++ b/packages/astro/test/astro-client-only.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import { load as cheerioLoad } from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Client only components', () => { @@ -20,10 +21,10 @@ describe('Client only components', () => { const $ = cheerioLoad(html); // test 1: <astro-island> is empty - expect($('astro-island').html()).to.equal(''); + assert.equal($('astro-island').html(), ''); // test 2: svelte renderer is on the page - expect($('astro-island').attr('renderer-url')).to.be.ok; + assert.ok($('astro-island').attr('renderer-url')); }); it('Adds the CSS to the page', async () => { @@ -38,32 +39,32 @@ describe('Client only components', () => { const css = stylesheets.join(''); // yellowgreen minified - expect(css).to.contain('#9acd32', 'Svelte styles are added'); - expect(css).to.include('Courier New', 'Global styles are added'); + assert.match(css, /#9acd32/, 'Svelte styles are added'); + assert.match(css, /Courier New/, 'Global styles are added'); }); it('Adds the CSS to the page - standalone svelte component', async () => { const html = await fixture.readFile('/persistent-counter-standalone/index.html'); const $ = cheerioLoad(html); - expect($('head link[rel=stylesheet]')).to.have.a.lengthOf(1); + assert.equal($('head link[rel=stylesheet]').length, 1); const href = $('link[rel=stylesheet]').attr('href'); const css = await fixture.readFile(href); - expect(css).to.match(/tomato/, 'Svelte styles are added'); + assert.match(css, /tomato/, 'Svelte styles are added'); }); it('Includes CSS from components that use CSS modules', async () => { const html = await fixture.readFile('/css-modules/index.html'); const $ = cheerioLoad(html); - expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1); + assert.equal($('link[rel=stylesheet]').length, 1); }); it('Includes CSS from package components', async () => { const html = await fixture.readFile('/pkg/index.html'); const $ = cheerioLoad(html); - expect($('link[rel=stylesheet]')).to.have.a.lengthOf(1); + assert.equal($('link[rel=stylesheet]').length, 1); }); }); @@ -86,10 +87,10 @@ describe('Client only components subpath', () => { const $ = cheerioLoad(html); // test 1: <astro-island> is empty - expect($('astro-island').html()).to.equal(''); + assert.equal($('astro-island').html(), ''); // test 2: svelte renderer is on the page - expect($('astro-island').attr('renderer-url')).to.be.ok; + assert.ok($('astro-island').attr('renderer-url')); }); it('Adds the CSS to the page', async () => { @@ -104,8 +105,8 @@ describe('Client only components subpath', () => { const css = stylesheets.join(''); // yellowgreen minified - expect(css).to.contain('#9acd32', 'Svelte styles are added'); - expect(css).to.include('Courier New', 'Global styles are added'); + assert.match(css, /#9acd32/, 'Svelte styles are added'); + assert.match(css, /Courier New/, 'Global styles are added'); }); it('Adds the CSS to the page for TSX components', async () => { @@ -115,6 +116,6 @@ describe('Client only components subpath', () => { const href = $('link[rel=stylesheet]').attr('href'); const css = await fixture.readFile(href.replace(/\/blog/, '')); - expect(css).to.match(/purple/, 'Global styles from tsx component are added'); + assert.match(css, /purple/, 'Global styles from tsx component are added'); }); }); diff --git a/packages/astro/test/astro-component-code.test.js b/packages/astro/test/astro-component-code.nodetest.js index dbca3f56d..1a3a23ea7 100644 --- a/packages/astro/test/astro-component-code.test.js +++ b/packages/astro/test/astro-component-code.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('<Code>', () => { @@ -13,33 +14,35 @@ describe('<Code>', () => { it('<Code> without lang or theme', async () => { let html = await fixture.readFile('/no-lang/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); - expect($('pre').attr('style')).to.equal( + assert.equal($('pre').length, 1); + assert.equal( + $('pre').attr('style'), 'background-color:#24292e;color:#e1e4e8; overflow-x: auto;', 'applies default and overflow' ); - expect($('pre > code')).to.have.lengthOf(1); + assert.equal($('pre > code').length, 1); // test: contains some generated spans - expect($('pre > code span').length).to.be.greaterThan(1); + assert.equal($('pre > code span').length > 1, true); }); it('<Code lang="...">', async () => { let html = await fixture.readFile('/basic/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); - expect($('pre').attr('class'), 'astro-code nord'); - expect($('pre > code')).to.have.lengthOf(1); + assert.equal($('pre').length, 1); + assert.equal($('pre').attr('class'), 'astro-code github-dark'); + assert.equal($('pre > code').length, 1); // test: contains many generated spans - expect($('pre > code span').length).to.be.greaterThanOrEqual(6); + assert.equal($('pre > code span').length >= 6, true); }); it('<Code theme="...">', async () => { let html = await fixture.readFile('/custom-theme/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); - expect($('pre').attr('class')).to.equal('astro-code nord'); - expect($('pre').attr('style')).to.equal( + assert.equal($('pre').length, 1); + assert.equal($('pre').attr('class'), 'astro-code nord'); + assert.equal( + $('pre').attr('style'), 'background-color:#2e3440ff;color:#d8dee9ff; overflow-x: auto;', 'applies custom theme' ); @@ -49,58 +52,64 @@ describe('<Code>', () => { { let html = await fixture.readFile('/wrap-true/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); + assert.equal($('pre').length, 1); // test: applies wrap overflow - expect($('pre').attr('style')).to.equal( + assert.equal( + $('pre').attr('style'), 'background-color:#24292e;color:#e1e4e8; overflow-x: auto; white-space: pre-wrap; word-wrap: break-word;' ); } { let html = await fixture.readFile('/wrap-false/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); + assert.equal($('pre').length, 1); // test: applies wrap overflow - expect($('pre').attr('style')).to.equal( + assert.equal( + $('pre').attr('style'), 'background-color:#24292e;color:#e1e4e8; overflow-x: auto;' ); } { let html = await fixture.readFile('/wrap-null/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); + assert.equal($('pre').length, 1); // test: applies wrap overflow - expect($('pre').attr('style')).to.equal('background-color:#24292e;color:#e1e4e8'); + assert.equal($('pre').attr('style'), 'background-color:#24292e;color:#e1e4e8'); } }); it('<Code lang="..." theme="css-variables">', async () => { let html = await fixture.readFile('/css-theme/index.html'); const $ = cheerio.load(html); - expect($('pre')).to.have.lengthOf(1); - expect($('pre').attr('class')).to.equal('astro-code css-variables'); - expect( + assert.equal($('pre').length, 1); + assert.equal($('pre').attr('class'), 'astro-code css-variables'); + assert.deepEqual( $('pre, pre span') .map((i, f) => (f.attribs ? f.attribs.style : 'no style found')) - .toArray() - ).to.deep.equal([ - 'background-color:var(--astro-code-color-background);color:var(--astro-code-color-text); overflow-x: auto;', - 'color:var(--astro-code-token-constant)', - 'color:var(--astro-code-token-function)', - 'color:var(--astro-code-color-text)', - 'color:var(--astro-code-token-string-expression)', - 'color:var(--astro-code-color-text)', - ]); + .toArray(), + [ + 'background-color:var(--astro-code-color-background);color:var(--astro-code-color-text); overflow-x: auto;', + 'color:var(--astro-code-token-constant)', + 'color:var(--astro-code-token-function)', + 'color:var(--astro-code-color-text)', + 'color:var(--astro-code-token-string-expression)', + 'color:var(--astro-code-color-text)', + ] + ); }); it('<Code> with custom theme and lang', async () => { let html = await fixture.readFile('/imported/index.html'); const $ = cheerio.load(html); - expect($('#theme > pre')).to.have.lengthOf(1); - expect($('#theme > pre').attr('style'), 'background-color: #FDFDFE; overflow-x: auto;'); + assert.equal($('#theme > pre').length, 1); + assert.equal( + $('#theme > pre').attr('style'), + 'background-color:#FDFDFE;color:#4E5377; overflow-x: auto;' + ); - expect($('#lang > pre')).to.have.lengthOf(1); - expect($('#lang > pre > code span').length).to.equal(3); + assert.equal($('#lang > pre').length, 1); + assert.equal($('#lang > pre > code span').length, 3); }); it('<Code inline> has no pre tag', async () => { @@ -108,8 +117,8 @@ describe('<Code>', () => { const $ = cheerio.load(html); const codeEl = $('.astro-code'); - expect(codeEl.prop('tagName')).to.eq('CODE'); - expect(codeEl.attr('style')).to.include('background-color:'); - expect($('pre')).to.have.lengthOf(0); + assert.equal(codeEl.prop('tagName'), 'CODE'); + assert.match(codeEl.attr('style'), /background-color:/); + assert.equal($('pre').length, 0); }); }); diff --git a/packages/astro/test/astro-cookies.test.js b/packages/astro/test/astro-cookies.nodetest.js index e201ebd87..34f548109 100644 --- a/packages/astro/test/astro-cookies.test.js +++ b/packages/astro/test/astro-cookies.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; import testAdapter from './test-adapter.js'; @@ -33,22 +34,22 @@ describe('Astro.cookies', () => { cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, }, }); - expect(response.status).to.equal(200); + assert.equal(response.status, 200); const html = await response.text(); const $ = cheerio.load(html); - expect($('dd').text()).to.equal('light'); + assert.equal($('dd').text(), 'light'); }); it('can set the cookie value', async () => { const response = await fixture.fetch('/set-value', { method: 'POST', }); - expect(response.status).to.equal(200); + assert.equal(response.status, 200); // Bug in 18.14.1 where `set-cookie` will not be defined // Should be fixed in 18.14.2 if (process.versions.node !== '18.14.1') { - expect(response.headers.has('set-cookie')).to.equal(true); + assert.equal(response.headers.has('set-cookie'), true); } }); }); @@ -72,21 +73,21 @@ describe('Astro.cookies', () => { cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, }, }); - expect(response.status).to.equal(200); + assert.equal(response.status, 200); const html = await response.text(); const $ = cheerio.load(html); - expect($('dd').text()).to.equal('light'); + assert.equal($('dd').text(), 'light'); }); it('can set the cookie value', async () => { const response = await fetchResponse('/set-value', { method: 'POST', }); - expect(response.status).to.equal(200); + assert.equal(response.status, 200); let headers = Array.from(app.setCookieHeaders(response)); - expect(headers).to.have.a.lengthOf(1); - expect(headers[0]).to.match(/Expires/); + assert.equal(headers.length, 1); + assert.match(headers[0], /Expires/); }); it('app.render can include the cookie in the Set-Cookie header', async () => { @@ -94,10 +95,10 @@ describe('Astro.cookies', () => { method: 'POST', }); const response = await app.render(request, { addCookieHeader: true }); - expect(response.status).to.equal(200); - expect(response.headers.get('Set-Cookie')) - .to.be.a('string') - .and.satisfy((value) => value.startsWith('admin=true; Expires=')); + assert.equal(response.status, 200); + const value = response.headers.get('Set-Cookie'); + assert.equal(typeof value, 'string'); + assert.equal(value.startsWith('admin=true; Expires='), true); }); it('app.render can exclude the cookie from the Set-Cookie header', async () => { @@ -105,8 +106,8 @@ describe('Astro.cookies', () => { method: 'POST', }); const response = await app.render(request, { addCookieHeader: false }); - expect(response.status).to.equal(200); - expect(response.headers.get('Set-Cookie')).to.equal(null); + assert.equal(response.status, 200); + assert.equal(response.headers.get('Set-Cookie'), null); }); it('Early returning a Response still includes set headers', async () => { @@ -115,13 +116,13 @@ describe('Astro.cookies', () => { cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, }, }); - expect(response.status).to.equal(302); + assert.equal(response.status, 302); let headers = Array.from(app.setCookieHeaders(response)); - expect(headers).to.have.a.lengthOf(1); + assert.equal(headers.length, 1); let raw = headers[0].slice(6); let data = JSON.parse(decodeURIComponent(raw)); - expect(data).to.be.an('object'); - expect(data.mode).to.equal('dark'); + assert.equal(typeof data, 'object'); + assert.equal(data.mode, 'dark'); }); it('API route can get and set cookies', async () => { @@ -131,13 +132,13 @@ describe('Astro.cookies', () => { cookie: `prefs=${encodeURIComponent(JSON.stringify({ mode: 'light' }))}`, }, }); - expect(response.status).to.equal(302); + assert.equal(response.status, 302); let headers = Array.from(app.setCookieHeaders(response)); - expect(headers).to.have.a.lengthOf(1); + assert.equal(headers.length, 1); let raw = headers[0].slice(6); let data = JSON.parse(decodeURIComponent(raw)); - expect(data).to.be.an('object'); - expect(data.mode).to.equal('dark'); + assert.equal(typeof data, 'object'); + assert.equal(data.mode, 'dark'); }); }); }); diff --git a/packages/astro/test/astro-css-bundling.test.js b/packages/astro/test/astro-css-bundling.nodetest.js index 9143a782b..150f9a381 100644 --- a/packages/astro/test/astro-css-bundling.test.js +++ b/packages/astro/test/astro-css-bundling.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; // note: the hashes should be deterministic, but updating the file contents will change hashes @@ -43,7 +44,7 @@ describe('CSS Bundling', function () { // test 1: assert new bundled CSS is present for (const href of css) { const link = $(`link[rel="stylesheet"][href^="${href}"]`); - expect(link.length).to.be.greaterThanOrEqual(1); + assert.equal(link.length >= 1, true); const outHref = link.attr('href'); builtCSS.add(outHref.startsWith('../') ? outHref.slice(2) : outHref); } @@ -51,25 +52,25 @@ describe('CSS Bundling', function () { // test 2: assert old CSS was removed for (const href of UNEXPECTED_CSS) { const link = $(`link[rel="stylesheet"][href="${href}"]`); - expect(link).to.have.lengthOf(0); + assert.equal(link.length, 0); } // test 3: assert all bundled CSS was built and contains CSS for (const url of builtCSS.keys()) { const bundledCss = await fixture.readFile(url); - expect(bundledCss).to.be.ok; + assert.ok(bundledCss); } } }); it('there are 4 css files', async () => { const dir = await fixture.readdir('/_astro'); - expect(dir).to.have.a.lengthOf(4); + assert.equal(dir.length, 4); }); it('CSS includes hashes', async () => { const [firstFound] = await fixture.readdir('/_astro'); - expect(firstFound).to.match(/[a-z]+\.[\w-]{8}\.css/); + assert.match(firstFound, /[a-z]+\.[\w-]{8}\.css/); }); }); @@ -97,18 +98,18 @@ describe('CSS Bundling', function () { it('there are 4 css files', async () => { const dir = await fixture.readdir('/assets'); - expect(dir).to.have.a.lengthOf(4); + assert.equal(dir.length, 4); }); it('CSS does not include hashes', async () => { const [firstFound] = await fixture.readdir('/assets'); - expect(firstFound).to.not.match(/[a-z]+\.[\da-z]{8}\.css/); + assert.doesNotMatch(firstFound, /[a-z]+\.[\da-z]{8}\.css/); }); it('there are 2 index named CSS files', async () => { const dir = await fixture.readdir('/assets'); const indexNamedFiles = dir.filter((name) => name.startsWith('index')); - expect(indexNamedFiles).to.have.a.lengthOf(2); + assert.equal(indexNamedFiles.length, 2); }); }); }); diff --git a/packages/astro/test/astro-dev-headers.test.js b/packages/astro/test/astro-dev-headers.nodetest.js index 7cc2266c6..e119e365a 100644 --- a/packages/astro/test/astro-dev-headers.test.js +++ b/packages/astro/test/astro-dev-headers.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Astro dev headers', () => { @@ -26,14 +27,14 @@ describe('Astro dev headers', () => { describe('dev', () => { it('returns custom headers for valid URLs', async () => { const result = await fixture.fetch('/'); - expect(result.status).to.equal(200); - expect(Object.fromEntries(result.headers)).to.include(headers); + assert.equal(result.status, 200); + assert.equal(Object.fromEntries(result.headers)['x-astro'], headers['x-astro']); }); it('does not return custom headers for invalid URLs', async () => { const result = await fixture.fetch('/bad-url'); - expect(result.status).to.equal(404); - expect(Object.fromEntries(result.headers)).not.to.include(headers); + assert.equal(result.status, 404); + assert.equal(Object.fromEntries(result.headers).hasOwnProperty('x-astro'), false); }); }); }); diff --git a/packages/astro/test/astro-directives.test.js b/packages/astro/test/astro-directives.nodetest.js index 4ce5ee916..5b9e0b672 100644 --- a/packages/astro/test/astro-directives.test.js +++ b/packages/astro/test/astro-directives.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Directives', async () => { @@ -18,25 +19,25 @@ describe('Directives', async () => { const html = await fixture.readFile('/define-vars/index.html'); const $ = cheerio.load(html); - expect($('script')).to.have.lengthOf(5); + assert.equal($('script').length, 5); let i = 0; for (const script of $('script').toArray()) { // Wrap script in scope ({}) to avoid redeclaration errors - expect($(script).text().startsWith('(function(){')).to.equal(true); - expect($(script).text().endsWith('})();')).to.equal(true); + assert.equal($(script).text().startsWith('(function(){'), true); + assert.equal($(script).text().endsWith('})();'), true); if (i < 2) { // Inline defined variables - expect($(script).toString()).to.include('const foo = "bar"'); + assert.equal($(script).toString().includes('const foo = "bar"'), true); } else if (i < 3) { // Convert invalid keys to valid identifiers - expect($(script).toString()).to.include('const dashCase = "bar"'); + assert.equal($(script).toString().includes('const dashCase = "bar"'), true); } else if (i < 4) { // Closing script tags in strings are escaped - expect($(script).toString()).to.include('const bar = "<script>bar\\x3C/script>"'); + assert.equal($(script).toString().includes('const bar = "<script>bar\\x3C/script>"'), true); } else { // Vars with undefined values are handled - expect($(script).toString()).to.include('const undef = undefined'); + assert.equal($(script).toString().includes('const undef = undefined'), true); } i++; } @@ -47,14 +48,14 @@ describe('Directives', async () => { const $ = cheerio.load(html); // All styles should be bundled - expect($('style')).to.have.lengthOf(0); + assert.equal($('style').length, 0); // Inject style attribute on top-level element in page - expect($('html').attr('style').toString()).to.include('--bg: white;'); - expect($('html').attr('style').toString()).to.include('--fg: black;'); + assert.equal($('html').attr('style').toString().includes('--bg: white;'), true); + assert.equal($('html').attr('style').toString().includes('--fg: black;'), true); // Inject style attribute on top-level elements in component - expect($('h1').attr('style').toString()).to.include('--textColor: red;'); + assert.equal($('h1').attr('style').toString().includes('--textColor: red;'), true); }); it('Properly handles define:vars on style elements with style object', async () => { @@ -62,11 +63,15 @@ describe('Directives', async () => { const $ = cheerio.load(html); // All styles should be bundled - expect($('style')).to.have.lengthOf(0); + assert.equal($('style').length, 0); // Inject style attribute on top-level element in page - expect($('#compound-style').attr('style').toString()).to.include( - 'color:var(--fg);--fg: black;--bg: white;' + assert.equal( + $('#compound-style') + .attr('style') + .toString() + .includes('color:var(--fg);--fg: black;--bg: white;'), + true ); }); @@ -74,25 +79,25 @@ describe('Directives', async () => { const html = await fixture.readFile('/set-html/index.html'); const $ = cheerio.load(html); - expect($('#text')).to.have.lengthOf(1); - expect($('#text').text()).to.equal('a'); + assert.equal($('#text').length, 1); + assert.equal($('#text').text(), 'a'); - expect($('#zero')).to.have.lengthOf(1); - expect($('#zero').text()).to.equal('0'); + assert.equal($('#zero').length, 1); + assert.equal($('#zero').text(), '0'); - expect($('#number')).to.have.lengthOf(1); - expect($('#number').text()).to.equal('1'); + assert.equal($('#number').length, 1); + assert.equal($('#number').text(), '1'); - expect($('#undefined')).to.have.lengthOf(1); - expect($('#undefined').text()).to.equal(''); + assert.equal($('#undefined').length, 1); + assert.equal($('#undefined').text(), ''); - expect($('#null')).to.have.lengthOf(1); - expect($('#null').text()).to.equal(''); + assert.equal($('#null').length, 1); + assert.equal($('#null').text(), ''); - expect($('#false')).to.have.lengthOf(1); - expect($('#false').text()).to.equal(''); + assert.equal($('#false').length, 1); + assert.equal($('#false').text(), ''); - expect($('#true')).to.have.lengthOf(1); - expect($('#true').text()).to.equal('true'); + assert.equal($('#true').length, 1); + assert.equal($('#true').text(), 'true'); }); }); diff --git a/packages/astro/test/astro-doctype.test.js b/packages/astro/test/astro-doctype.nodetest.js index 8c954141e..ada762d82 100644 --- a/packages/astro/test/astro-doctype.test.js +++ b/packages/astro/test/astro-doctype.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Doctype', () => { @@ -14,21 +15,22 @@ describe('Doctype', () => { const html = await fixture.readFile('/prepend/index.html'); // test that Doctype always included - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); }); it('No attributes added when doctype is provided by user', async () => { const html = await fixture.readFile('/provided/index.html'); // test that Doctype always included - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); }); it.skip('Preserves user provided doctype', async () => { const html = await fixture.readFile('/preserve/index.html'); // test that Doctype included was preserved - expect(html).to.match( + assert.match( + html, /^<!DOCTYPE html PUBLIC "-\/\/W3C\/\/DTD HTML 4.01 Transitional\/\/EN" "http:\/\/www.w3.org\/TR\/html4\/loose.dtd">/i ); }); @@ -37,38 +39,38 @@ describe('Doctype', () => { const html = await fixture.readFile('/capital/index.html'); // test 1: Doctype left alone - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); // test 2: no closing tag - expect(html).not.to.match(/<\/!DOCTYPE>/i); + assert.doesNotMatch(html, /<\/!DOCTYPE>/i); }); it.skip('Doctype can be provided in a layout', async () => { const html = await fixture.readFile('/in-layout/index.html'); // test 1: doctype is at the front - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); // test 2: A link inside of the head const $ = cheerio.load(html); - expect($('head link')).to.have.lengthOf(1); + assert.equal($('head link').length, 1); }); it('Doctype is added in a layout without one', async () => { const html = await fixture.readFile('/in-layout-no-doctype/index.html'); // test that doctype is at the front - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); }); it('Doctype is added in a layout used with markdown pages', async () => { const html = await fixture.readFile('/in-layout-article/index.html'); // test 1: doctype is at the front - expect(html).to.match(/^<!DOCTYPE html>/i); + assert.match(html, /^<!DOCTYPE html>/i); // test 2: A link inside of the head const $ = cheerio.load(html); - expect($('head link')).to.have.lengthOf(1); + assert.equal($('head link').length, 1); }); }); diff --git a/packages/astro/test/astro-dynamic.test.js b/packages/astro/test/astro-dynamic.nodetest.js index 5d91815ba..63ed2582a 100644 --- a/packages/astro/test/astro-dynamic.test.js +++ b/packages/astro/test/astro-dynamic.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Dynamic components', () => { @@ -16,7 +17,7 @@ describe('Dynamic components', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('script').length).to.eq(1); + assert.equal($('script').length, 1); }); it('Loads pages using client:media hydrator', async () => { @@ -24,7 +25,7 @@ describe('Dynamic components', () => { const $ = cheerio.load(html); // test 1: static value rendered - expect($('script').length).to.equal(1); + assert.equal($('script').length, 1); }); it('Loads pages using client:only hydrator', async () => { @@ -32,10 +33,10 @@ describe('Dynamic components', () => { const $ = cheerio.load(html); // test 1: <astro-island> is empty. - expect($('astro-island').html()).to.equal(''); + assert.equal($('astro-island').html(), ''); // test 2: component url const href = $('astro-island').attr('component-url'); - expect(href).to.include(`/PersistentCounter`); + assert.equal(href.includes(`/PersistentCounter`), true); }); }); @@ -55,7 +56,7 @@ describe('Dynamic components subpath', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('script').length).to.eq(1); + assert.equal($('script').length, 1); }); it('Loads pages using client:media hydrator', async () => { @@ -63,7 +64,7 @@ describe('Dynamic components subpath', () => { const $ = cheerio.load(html); // test 1: static value rendered - expect($('script').length).to.equal(1); + assert.equal($('script').length, 1); }); it('Loads pages using client:only hydrator', async () => { @@ -71,9 +72,9 @@ describe('Dynamic components subpath', () => { const $ = cheerio.load(html); // test 1: <astro-island> is empty. - expect($('astro-island').html()).to.equal(''); + assert.equal($('astro-island').html(), ''); // test 2: has component url const attr = $('astro-island').attr('component-url'); - expect(attr).to.include(`blog/_astro/PersistentCounter`); + assert.equal(attr.includes(`blog/_astro/PersistentCounter`), true); }); }); diff --git a/packages/astro/test/astro-envs.test.js b/packages/astro/test/astro-envs.nodetest.js index c923ae065..b477b0394 100644 --- a/packages/astro/test/astro-envs.test.js +++ b/packages/astro/test/astro-envs.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; import * as cheerio from 'cheerio'; @@ -18,37 +19,37 @@ describe('Environment Variables', () => { }); it('builds without throwing', async () => { - expect(true).to.equal(true); + assert.equal(true, true); }); it('does render public env and private env', async () => { let indexHtml = await fixture.readFile('/index.html'); - expect(indexHtml).to.include('CLUB_33'); - expect(indexHtml).to.include('BLUE_BAYOU'); + assert.equal(indexHtml.includes('CLUB_33'), true); + assert.equal(indexHtml.includes('BLUE_BAYOU'), true); }); it('does render destructured public env and private env', async () => { let indexHtml = await fixture.readFile('/destructured/index.html'); - expect(indexHtml).to.include('CLUB_33'); - expect(indexHtml).to.include('BLUE_BAYOU'); + assert.equal(indexHtml.includes('CLUB_33'), true); + assert.equal(indexHtml.includes('BLUE_BAYOU'), true); }); it('does render builtin SITE env', async () => { let indexHtml = await fixture.readFile('/index.html'); - expect(indexHtml).to.include('http://example.com'); + assert.equal(indexHtml.includes('http://example.com'), true); }); it('does render destructured builtin SITE env', async () => { let indexHtml = await fixture.readFile('/destructured/index.html'); - expect(indexHtml).to.include('http://example.com'); + assert.equal(indexHtml.includes('http://example.com'), true); }); it('does render builtin BASE_URL env', async () => { let indexHtml = await fixture.readFile('/index.html'); - expect(indexHtml).to.include('/blog'); + assert.equal(indexHtml.includes('/blog'), true); }); it('includes public env in client-side JS', async () => { @@ -69,7 +70,7 @@ describe('Environment Variables', () => { }) ); - expect(found).to.equal(true, 'found the public env variable in the JS build'); + assert.equal(found, true, 'found the public env variable in the JS build'); }); it('does not include private env in client-side JS', async () => { @@ -90,7 +91,7 @@ describe('Environment Variables', () => { }) ); - expect(found).to.equal(false, 'found the private env variable in the JS build'); + assert.equal(found, false, 'found the private env variable in the JS build'); }); }); @@ -106,18 +107,18 @@ describe('Environment Variables', () => { it('does render builtin BASE_URL env', async () => { let res = await fixture.fetch('/blog/'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); let indexHtml = await res.text(); let $ = cheerio.load(indexHtml); - expect($('#base-url').text()).to.equal('/blog'); + assert.equal($('#base-url').text(), '/blog'); }); it('does render destructured builtin SITE env', async () => { let res = await fixture.fetch('/blog/destructured/'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); let indexHtml = await res.text(); let $ = cheerio.load(indexHtml); - expect($('#base-url').text()).to.equal('/blog'); + assert.equal($('#base-url').text(), '/blog'); }); }); }); diff --git a/packages/astro/test/astro-expr.test.js b/packages/astro/test/astro-expr.nodetest.js index 33a976d33..48e73c6c8 100644 --- a/packages/astro/test/astro-expr.test.js +++ b/packages/astro/test/astro-expr.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Expressions', () => { @@ -17,7 +18,7 @@ describe('Expressions', () => { const $ = cheerio.load(html); for (let col of ['red', 'yellow', 'blue']) { - expect($('#' + col)).to.have.lengthOf(1); + assert.equal($('#' + col).length, 1); } }); @@ -26,7 +27,7 @@ describe('Expressions', () => { const $ = cheerio.load(html); for (let col of ['red', 'yellow', 'blue']) { - expect($('#' + col)).to.have.lengthOf(1); + assert.equal($('#' + col).length, 1); } }); @@ -35,7 +36,7 @@ describe('Expressions', () => { const $ = cheerio.load(html); for (let col of ['red', 'yellow', 'blue']) { - expect($('#' + col)).to.have.lengthOf(1); + assert.equal($('#' + col).length, 1); } }); @@ -44,25 +45,25 @@ describe('Expressions', () => { const $ = cheerio.load(html); for (let col of ['red', 'yellow', 'blue']) { - expect($('#' + col)).to.have.lengthOf(1); + assert.equal($('#' + col).length, 1); } }); it('Allows multiple JSX children in mustache', async () => { const html = await fixture.readFile('/multiple-children/index.html'); - expect(html).to.include('#f'); - expect(html).not.to.include('#t'); + assert.equal(html.includes('#f'), true); + assert.equal(html.includes('#t'), false); }); it('Allows <> Fragments in expressions', async () => { const html = await fixture.readFile('/multiple-children/index.html'); const $ = cheerio.load(html); - expect($('#fragment').children()).to.have.lengthOf(3); - expect($('#fragment').children('#a')).to.have.lengthOf(1); - expect($('#fragment').children('#b')).to.have.lengthOf(1); - expect($('#fragment').children('#c')).to.have.lengthOf(1); + assert.equal($('#fragment').children().length, 3); + assert.equal($('#fragment').children('#a').length, 1); + assert.equal($('#fragment').children('#b').length, 1); + assert.equal($('#fragment').children('#c').length, 1); }); it('Does not render falsy values using &&', async () => { @@ -70,57 +71,60 @@ describe('Expressions', () => { const $ = cheerio.load(html); // test 1: Expected {true && <span id="true" />} to render - expect($('#true')).to.have.lengthOf(1); + assert.equal($('#true').length, 1); // test 2: Expected {0 && "VALUE"} to render "0" - expect($('#zero').text()).to.equal('0'); + assert.equal($('#zero').text(), '0'); // test 3: Expected {false && <span id="false" />} not to render - expect($('#false')).to.have.lengthOf(0); + assert.equal($('#false').length, 0); // test 4: Expected {null && <span id="null" />} not to render - expect($('#null')).to.have.lengthOf(0); + assert.equal($('#null').length, 0); // test 5: Expected {undefined && <span id="undefined" />} not to render - expect($('#undefined')).to.have.lengthOf(0); + assert.equal($('#undefined').length, 0); // Inside of a component // test 6: Expected {true && <span id="true" />} to render - expect($('#frag-true')).to.have.lengthOf(1); + assert.equal($('#frag-true').length, 1); // test 7: Expected {false && <span id="false" />} not to render - expect($('#frag-false')).to.have.lengthOf(0); + assert.equal($('#frag-false').length, 0); // test 8: Expected {null && <span id="null" />} not to render - expect($('#frag-null')).to.have.lengthOf(0); + assert.equal($('#frag-null').length, 0); // test 9: Expected {undefined && <span id="undefined" />} not to render - expect($('#frag-undefined')).to.have.lengthOf(0); + assert.equal($('#frag-undefined').length, 0); }); it('Escapes HTML by default', async () => { const html = await fixture.readFile('/escape/index.html'); const $ = cheerio.load(html); - expect($('body').children()).to.have.lengthOf(2); - expect($('body').html()).to.include('<script>console.log("pwnd")</script>'); - expect($('#trusted')).to.have.lengthOf(1); + assert.equal($('body').children().length, 2); + assert.equal( + $('body').html().includes('<script>console.log("pwnd")</script>'), + true + ); + assert.equal($('#trusted').length, 1); }); it('Does not double-escape HTML', async () => { const html = await fixture.readFile('/escape/index.html'); const $ = cheerio.load(html); - expect($('#single-escape').html()).to.equal('Astro & Vite'); + assert.equal($('#single-escape').html(), 'Astro & Vite'); }); it('Handles switch statements', async () => { const html = await fixture.readFile('/switch/index.html'); const $ = cheerio.load(html); - expect($('#red').length).to.equal(0); - expect($('#yellow').length).to.equal(1); - expect($('#blue').length).to.equal(0); + assert.equal($('#red').length, 0); + assert.equal($('#yellow').length, 1); + assert.equal($('#blue').length, 0); }); }); diff --git a/packages/astro/test/astro-fallback.test.js b/packages/astro/test/astro-fallback.nodetest.js index dd0c793fb..2cc36bdbc 100644 --- a/packages/astro/test/astro-fallback.test.js +++ b/packages/astro/test/astro-fallback.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Dynamic component fallback', () => { @@ -15,6 +16,6 @@ describe('Dynamic component fallback', () => { it('Shows static content', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('#fallback').text()).to.equal('static'); + assert.equal($('#fallback').text(), 'static'); }); }); diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.nodetest.js index 3e35d6c85..390879c65 100644 --- a/packages/astro/test/astro-get-static-paths.test.js +++ b/packages/astro/test/astro-get-static-paths.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, afterEach, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('getStaticPaths - build calls', () => { @@ -23,14 +24,14 @@ describe('getStaticPaths - build calls', () => { it('is only called once during build', () => { // useless expect; if build() throws in setup then this test fails - expect(true).to.equal(true); + assert.equal(true, true); }); it('Astro.url sets the current pathname', async () => { const html = await fixture.readFile('/food/tacos/index.html'); const $ = cheerio.load(html); - expect($('#url').text()).to.equal('/blog/food/tacos'); + assert.equal($('#url').text(), '/blog/food/tacos'); }); }); @@ -56,39 +57,35 @@ describe('getStaticPaths - dev calls', () => { }); it('only calls getStaticPaths once', async function () { - // Sometimes this fail in CI as the chokidar watcher triggers an update and invalidates the route cache, - // causing getStaticPaths to be called twice. Workaround this with 2 retries for now. - this.retries(2); - let res = await fixture.fetch('/a'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); res = await fixture.fetch('/b'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); res = await fixture.fetch('/c'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); describe('404 behavior', () => { it('resolves 200 on matching static path - named params', async () => { const res = await fixture.fetch('/pizza/provolone-sausage'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); it('resolves 404 on pattern match without static path - named params', async () => { const res = await fixture.fetch('/pizza/provolone-pineapple'); - expect(res.status).to.equal(404); + assert.equal(res.status, 404); }); it('resolves 200 on matching static path - rest params', async () => { const res = await fixture.fetch('/pizza/grimaldis/new-york'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); it('resolves 404 on pattern match without static path - rest params', async () => { const res = await fixture.fetch('/pizza/pizza-hut'); - expect(res.status).to.equal(404); + assert.equal(res.status, 404); }); }); @@ -96,13 +93,13 @@ describe('getStaticPaths - dev calls', () => { it('resolves 200 on matching static path - string params', async () => { // route provided with { params: { year: "2022", slug: "post-2" }} const res = await fixture.fetch('/blog/2022/post-1'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); it('resolves 200 on matching static path - numeric params', async () => { // route provided with { params: { year: 2022, slug: "post-2" }} const res = await fixture.fetch('/blog/2022/post-2'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); }); @@ -110,13 +107,14 @@ describe('getStaticPaths - dev calls', () => { // routes params provided for pages /posts/1, /posts/2, and /posts/3 for (const page of [1, 2, 3]) { let res = await fixture.fetch(`/posts/${page}`); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); const html = await res.text(); const $ = cheerio.load(html); const canonical = $('link[rel=canonical]'); - expect(canonical.attr('href')).to.equal( + assert.equal( + canonical.attr('href'), `https://mysite.dev/posts/${page}`, `doesn't trim the /${page} route param` ); @@ -125,6 +123,6 @@ describe('getStaticPaths - dev calls', () => { it('properly handles hyphenation in getStaticPaths', async () => { const res = await fixture.fetch('/pizza/parmesan-and-olives'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); }); }); diff --git a/packages/astro/test/astro-global.test.js b/packages/astro/test/astro-global.nodetest.js index f003bc035..08e744dd8 100644 --- a/packages/astro/test/astro-global.test.js +++ b/packages/astro/test/astro-global.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Astro Global', () => { @@ -26,20 +27,21 @@ describe('Astro Global', () => { it('Astro.request.url', async () => { const res = await await fixture.fetch('/blog/?foo=42'); - expect(res.status).to.equal(200); + assert.equal(res.status, 200); const html = await res.text(); const $ = cheerio.load(html); - expect($('#pathname').text()).to.equal('/blog/'); - expect($('#searchparams').text()).to.equal('{}'); - expect($('#child-pathname').text()).to.equal('/blog/'); - expect($('#nested-child-pathname').text()).to.equal('/blog/'); + assert.equal($('#pathname').text(), '/blog/'); + assert.equal($('#searchparams').text(), '{}'); + assert.equal($('#child-pathname').text(), '/blog/'); + assert.equal($('#nested-child-pathname').text(), '/blog/'); }); it('Astro.glob() returned `url` metadata of each markdown file extensions DOES NOT include the extension', async () => { const html = await fixture.fetch('/blog/omit-markdown-extensions/').then((res) => res.text()); const $ = cheerio.load(html); - expect($('[data-any-url-contains-extension]').data('any-url-contains-extension')).to.equal( + assert.equal( + $('[data-any-url-contains-extension]').data('any-url-contains-extension'), false ); }); @@ -54,29 +56,29 @@ describe('Astro Global', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('#pathname').text()).to.equal('/blog'); - expect($('#searchparams').text()).to.equal('{}'); - expect($('#child-pathname').text()).to.equal('/blog'); - expect($('#nested-child-pathname').text()).to.equal('/blog'); + assert.equal($('#pathname').text(), '/blog'); + assert.equal($('#searchparams').text(), '{}'); + assert.equal($('#child-pathname').text(), '/blog'); + assert.equal($('#nested-child-pathname').text(), '/blog'); }); it('Astro.site', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('#site').attr('href')).to.equal('https://mysite.dev/blog/'); + assert.equal($('#site').attr('href'), 'https://mysite.dev/blog/'); }); it('Astro.glob() correctly returns an array of all posts', async () => { const html = await fixture.readFile('/posts/1/index.html'); const $ = cheerio.load(html); - expect($('.post-url').attr('href')).to.equal('/blog/post/post-2'); + assert.equal($('.post-url').attr('href'), '/blog/post/post-2'); }); it('Astro.glob() correctly returns meta info for MD and Astro files', async () => { const html = await fixture.readFile('/glob/index.html'); const $ = cheerio.load(html); - expect($('[data-file]').length).to.equal(8); - expect($('.post-url[href]').length).to.equal(8); + assert.equal($('[data-file]').length, 8); + assert.equal($('.post-url[href]').length, 8); }); }); }); @@ -105,10 +107,10 @@ describe('Astro Global Defaults', () => { }); it('Astro.request.url', async () => { - expect($('#pathname').text()).to.equal(''); - expect($('#searchparams').text()).to.equal(''); - expect($('#child-pathname').text()).to.equal(''); - expect($('#nested-child-pathname').text()).to.equal(''); + assert.equal($('#pathname').text(), ''); + assert.equal($('#searchparams').text(), ''); + assert.equal($('#child-pathname').text(), ''); + assert.equal($('#nested-child-pathname').text(), ''); }); }); @@ -121,16 +123,16 @@ describe('Astro Global Defaults', () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('#pathname').text()).to.equal('/'); - expect($('#searchparams').text()).to.equal('{}'); - expect($('#child-pathname').text()).to.equal('/'); - expect($('#nested-child-pathname').text()).to.equal('/'); + assert.equal($('#pathname').text(), '/'); + assert.equal($('#searchparams').text(), '{}'); + assert.equal($('#child-pathname').text(), '/'); + assert.equal($('#nested-child-pathname').text(), '/'); }); it('Astro.site', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('#site').attr('href')).to.equal(undefined); + assert.equal($('#site').attr('href'), undefined); }); }); }); diff --git a/packages/astro/test/astro-object-style.test.js b/packages/astro/test/astro-object-style.nodetest.js index adcc43bd9..5c620b8d9 100644 --- a/packages/astro/test/astro-object-style.test.js +++ b/packages/astro/test/astro-object-style.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Object style', async () => { @@ -14,19 +15,19 @@ describe('Object style', async () => { const html = await fixture.readFile('/index.html'); const $ = cheerio.load(html); - expect($('[style="background-color:green"]')).to.have.lengthOf(1); - expect($('[style="background-color:red"]')).to.have.lengthOf(1); - expect($('[style="background-color:blue"]')).to.have.lengthOf(1); - expect($(`[style='background-image:url("a")']`)).to.have.lengthOf(1); + assert.equal($('[style="background-color:green"]').length, 1); + assert.equal($('[style="background-color:red"]').length, 1); + assert.equal($('[style="background-color:blue"]').length, 1); + assert.equal($(`[style='background-image:url("a")']`).length, 1); }); it('Passes style attributes as expected to components', async () => { const html = await fixture.readFile('/component/index.html'); const $ = cheerio.load(html); - expect($('[style="background-color:green"]')).to.have.lengthOf(1); - expect($('[style="background-color:red"]')).to.have.lengthOf(1); - expect($('[style="background-color:blue"]')).to.have.lengthOf(1); - expect($(`[style='background-image:url("a")']`)).to.have.lengthOf(1); + assert.equal($('[style="background-color:green"]').length, 1); + assert.equal($('[style="background-color:red"]').length, 1); + assert.equal($('[style="background-color:blue"]').length, 1); + assert.equal($(`[style='background-image:url("a")']`).length, 1); }); }); diff --git a/packages/astro/test/astro-pages.test.js b/packages/astro/test/astro-pages.nodetest.js index 3d17b521d..0a1601c39 100644 --- a/packages/astro/test/astro-pages.test.js +++ b/packages/astro/test/astro-pages.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture, isWindows } from './test-utils.js'; describe('Pages', () => { @@ -19,14 +20,14 @@ describe('Pages', () => { const html = await fixture.readFile('/posts/name-with-index/index.html'); const $ = cheerio.load(html); - expect($('h1').text()).to.equal('Name with index'); + assert.equal($('h1').text(), 'Name with index'); }); it('Can find page with quotes in file name', async () => { const html = await fixture.readFile("/quotes'-work-too/index.html"); const $ = cheerio.load(html); - expect($('h1').text()).to.equal('Quotes work too'); + assert.equal($('h1').text(), 'Quotes work too'); }); }); @@ -47,12 +48,16 @@ describe('Pages', () => { const html = await fixture.fetch('/').then((res) => res.text()); const $ = cheerio.load(html); - expect($('#testing').length).to.be.greaterThan(0); + assert.equal($('#testing').length > 0, true); }); it('should have Vite client in dev', async () => { const html = await fixture.fetch('/').then((res) => res.text()); - expect(html).to.include('/@vite/client', 'Markdown page does not have Vite client for HMR'); + assert.equal( + html.includes('/@vite/client'), + true, + 'Markdown page does not have Vite client for HMR' + ); }); }); }); diff --git a/packages/astro/test/astro-partial-html.test.js b/packages/astro/test/astro-partial-html.nodetest.js index 83dccaf80..48024b35b 100644 --- a/packages/astro/test/astro-partial-html.test.js +++ b/packages/astro/test/astro-partial-html.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Partial HTML', async () => { @@ -22,11 +23,11 @@ describe('Partial HTML', async () => { const $ = cheerio.load(html); // test 1: Doctype first - expect(html).to.match(/^<!DOCTYPE html/); + assert.match(html, /^<!DOCTYPE html/); // test 2: correct CSS present const allInjectedStyles = $('style').text(); - expect(allInjectedStyles).to.match(/\[data-astro-cid-[^{]+\{color:red\}/); + assert.match(allInjectedStyles, /\[data-astro-cid-[^{]+\{color:red\}/); }); it('injects framework styles', async () => { @@ -34,16 +35,16 @@ describe('Partial HTML', async () => { const $ = cheerio.load(html); // test 1: Doctype first - expect(html).to.match(/^<!DOCTYPE html/); + assert.match(html, /^<!DOCTYPE html/); // test 2: link tag present const allInjectedStyles = $('style').text().replace(/\s*/g, ''); - expect(allInjectedStyles).to.match(/h1\{color:red;\}/); + assert.match(allInjectedStyles, /h1\{color:red;\}/); }); it('pages with a head, injection happens inside', async () => { const html = await fixture.fetch('/with-head').then((res) => res.text()); const $ = cheerio.load(html); - expect($('style')).to.have.lengthOf(1); + assert.equal($('style').length, 1); }); }); diff --git a/packages/astro/test/astro-preview-headers.test.js b/packages/astro/test/astro-preview-headers.nodetest.js index ef05399de..d33f46376 100644 --- a/packages/astro/test/astro-preview-headers.test.js +++ b/packages/astro/test/astro-preview-headers.nodetest.js @@ -1,4 +1,5 @@ -import { expect } from 'chai'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Astro preview headers', () => { @@ -27,14 +28,14 @@ describe('Astro preview headers', () => { describe('preview', () => { it('returns custom headers for valid URLs', async () => { const result = await fixture.fetch('/'); - expect(result.status).to.equal(200); - expect(Object.fromEntries(result.headers)).to.include(headers); + assert.equal(result.status, 200); + assert.equal(Object.fromEntries(result.headers).astro, headers.astro); }); it('does not return custom headers for invalid URLs', async () => { const result = await fixture.fetch('/bad-url'); - expect(result.status).to.equal(404); - expect(Object.fromEntries(result.headers)).not.to.include(headers); + assert.equal(result.status, 404); + assert.equal(Object.fromEntries(result.headers).hasOwnProperty('astro'), false); }); }); }); diff --git a/packages/astro/test/astro-scripts.test.js b/packages/astro/test/astro-scripts.nodetest.js index f36e24d92..a9cdc991b 100644 --- a/packages/astro/test/astro-scripts.test.js +++ b/packages/astro/test/astro-scripts.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { after, before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Scripts (hoisted and not)', () => { @@ -22,16 +23,16 @@ describe('Scripts (hoisted and not)', () => { const html = await fixture.readFile('/external/index.html'); const $ = cheerio.load(html); - expect($('head script[type="module"]:not([src="/regular_script.js"])')).to.have.lengthOf(1); - expect($('body script')).to.have.lengthOf(0); + assert.equal($('head script[type="module"]:not([src="/regular_script.js"])').length, 1); + assert.equal($('body script').length, 0); }); it('Moves inline scripts up', async () => { const html = await fixture.readFile('/inline/index.html'); const $ = cheerio.load(html); - expect($('head script[type="module"]')).to.have.lengthOf(1); - expect($('body script')).to.have.lengthOf(0); + assert.equal($('head script[type="module"]').length, 1); + assert.equal($('body script').length, 0); }); it('Inline page builds the scripts to a single bundle', async () => { @@ -41,17 +42,18 @@ describe('Scripts (hoisted and not)', () => { let $el = $('script'); // test 1: Just one entry module - expect($el).to.have.lengthOf(1); + assert.equal($el.length, 1); const src = $el.attr('src'); const inlineEntryJS = await fixture.readFile(src); // test 3: the JS exists - expect(inlineEntryJS).to.be.ok; + assert.ok(inlineEntryJS); // test 4: Inline imported JS is included - expect(inlineEntryJS).to.contain( - 'I AM IMPORTED INLINE', + assert.equal( + inlineEntryJS.includes('I AM IMPORTED INLINE'), + true, 'The inline imported JS is included in the bundle' ); }); @@ -60,8 +62,8 @@ describe('Scripts (hoisted and not)', () => { let html = await fixture.readFile('/inline-shared-one/index.html'); let $ = cheerio.load(html); - expect($('script')).to.have.lengthOf(1); - expect($('script').attr('src')).to.not.equal(undefined); + assert.equal($('script').length, 1); + assert.notEqual($('script').attr('src'), undefined); }); it('External page using non-hoist scripts that are modules are built standalone', async () => { @@ -69,11 +71,11 @@ describe('Scripts (hoisted and not)', () => { let $ = cheerio.load(external); // test 1: there is 1 scripts - expect($('script')).to.have.lengthOf(1); + assert.equal($('script').length, 1); // test 2: inside assets let entryURL = $('script').attr('src'); - expect(entryURL.includes('_astro/')).to.equal(true); + assert.equal(entryURL.includes('_astro/'), true); }); it('External page using non-hoist scripts that are not modules are built standalone', async () => { @@ -81,18 +83,18 @@ describe('Scripts (hoisted and not)', () => { let $ = cheerio.load(external); // test 1: there is 1 scripts - expect($('script')).to.have.lengthOf(1); + assert.equal($('script').length, 1); // test 2: inside assets let entryURL = $('script').attr('src'); - expect(entryURL.includes('_astro/')).to.equal(true); + assert.equal(entryURL.includes('_astro/'), true); }); it('Scripts added via Astro.glob are hoisted', async () => { let glob = await fixture.readFile('/glob/index.html'); let $ = cheerio.load(glob); - expect($('script[type="module"]').length).to.be.greaterThan(0); + assert.equal($('script[type="module"]').length > 0, true); }); it('Styles imported by hoisted scripts are included on the page', async () => { @@ -100,7 +102,7 @@ describe('Scripts (hoisted and not)', () => { let $ = cheerio.load(html); // Imported styles + tailwind - expect($('link[rel=stylesheet]')).to.have.a.lengthOf(2); + assert.equal($('link[rel=stylesheet]').length, 2); }); describe('Inlining', () => { @@ -119,14 +121,14 @@ describe('Scripts (hoisted and not)', () => { let $ = cheerio.load(external); // test 1: there are two scripts - expect($('script')).to.have.lengthOf(2); + assert.equal($('script').length, 2); let el = $('script').get(1); - expect($(el).attr('src')).to.equal(undefined, 'This should have been inlined'); + assert.equal($(el).attr('src'), undefined, 'This should have been inlined'); let externalEntryJS = $(el).text(); // test 2: the JS exists - expect(externalEntryJS).to.be.ok; + assert.ok(externalEntryJS); }); }); }); @@ -177,7 +179,7 @@ describe('Scripts (hoisted and not)', () => { found++; } }); - expect(found).to.equal(1); + assert.equal(found, 1); }); it('Using injectScript does not interfere', async () => { @@ -191,7 +193,7 @@ describe('Scripts (hoisted and not)', () => { found++; } }); - expect(found).to.equal(1); + assert.equal(found, 1); }); it('Injected scripts are injected to injected routes', async () => { @@ -205,7 +207,7 @@ describe('Scripts (hoisted and not)', () => { found++; } }); - expect(found).to.equal(1); + assert.equal(found, 1); }); }); }); diff --git a/packages/astro/test/astro-slots-nested.test.js b/packages/astro/test/astro-slots-nested.nodetest.js index 07d746292..7f924d709 100644 --- a/packages/astro/test/astro-slots-nested.test.js +++ b/packages/astro/test/astro-slots-nested.nodetest.js @@ -1,5 +1,6 @@ -import { expect } from 'chai'; import * as cheerio from 'cheerio'; +import assert from 'node:assert/strict'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('Nested Slots', () => { @@ -14,15 +15,15 @@ describe('Nested Slots', () => { it('Hidden nested slots see their hydration scripts hoisted', async () => { const html = await fixture.readFile('/hidden-nested/index.html'); const $ = cheerio.load(html); - expect($('script')).to.have.a.lengthOf(1, 'script rendered'); + assert.equal($('script').length, 1, 'script rendered'); const scriptInTemplate = $($('template')[0].children[0]).find('script'); - expect(scriptInTemplate).to.have.a.lengthOf(0, 'script defined outside of the inner template'); + assert.equal(scriptInTemplate.length, 0, 'script defined outside of the inner template'); }); it('Slots rendered via Astro.slots.render have the hydration script', async () => { const html = await fixture.readFile('/component-slot/index.html'); const $ = cheerio.load(html); - expect($('script')).to.have.a.lengthOf(1, 'script rendered'); + assert.equal($('script').length, 1, 'script rendered'); }); describe('Client components nested inside server-only framework components', () => { @@ -34,28 +35,28 @@ describe('Nested Slots', () => { }); it('react', () => { - expect($('#react astro-slot')).to.have.a.lengthOf(1); - expect($('#react astro-static-slot')).to.have.a.lengthOf(0); + assert.equal($('#react astro-slot').length, 1); + assert.equal($('#react astro-static-slot').length, 0); }); it('vue', () => { - expect($('#vue astro-slot')).to.have.a.lengthOf(1); - expect($('#vue astro-static-slot')).to.have.a.lengthOf(0); + assert.equal($('#vue astro-slot').length, 1); + assert.equal($('#vue astro-static-slot').length, 0); }); it('preact', () => { - expect($('#preact astro-slot')).to.have.a.lengthOf(1); - expect($('#preact astro-static-slot')).to.have.a.lengthOf(0); + assert.equal($('#preact astro-slot').length, 1); + assert.equal($('#preact astro-static-slot').length, 0); }); it('solid', () => { - expect($('#solid astro-slot')).to.have.a.lengthOf(1); - expect($('#solid astro-static-slot')).to.have.a.lengthOf(0); + assert.equal($('#solid astro-slot').length, 1); + assert.equal($('#solid astro-static-slot').length, 0); }); it('svelte', () => { - expect($('#svelte astro-slot')).to.have.a.lengthOf(1); - expect($('#svelte astro-static-slot')).to.have.a.lengthOf(0); + assert.equal($('#svelte astro-slot').length, 1); + assert.equal($('#svelte astro-static-slot').length, 0); }); }); }); diff --git a/packages/astro/test/astro-sync.test.js b/packages/astro/test/astro-sync.nodetest.js index ba436fe21..433dfd142 100644 --- a/packages/astro/test/astro-sync.test.js +++ b/packages/astro/test/astro-sync.nodetest.js @@ -1,5 +1,6 @@ +import assert from 'node:assert/strict'; import * as fs from 'node:fs'; -import { expect } from 'chai'; +import { before, describe, it } from 'node:test'; import { loadFixture } from './test-utils.js'; describe('astro sync', () => { @@ -22,10 +23,11 @@ describe('astro sync', () => { await fixture.sync({}, { fs: fsMock }); const expectedTypesFile = new URL('.astro/types.d.ts', fixture.config.root).href; - expect(writtenFiles).to.haveOwnProperty(expectedTypesFile); + assert.equal(writtenFiles.hasOwnProperty(expectedTypesFile), true); // smoke test `astro check` asserts whether content types pass. - expect(writtenFiles[expectedTypesFile]).to.include( - `declare module 'astro:content' {`, + assert.equal( + writtenFiles[expectedTypesFile].includes(`declare module 'astro:content' {`), + true, 'Types file does not include `astro:content` module declaration' ); }); @@ -57,8 +59,15 @@ describe('astro sync', () => { }; await fixture.sync({}, { fs: fsMock }); - expect(writtenFiles, 'Did not try to update env.d.ts file.').to.haveOwnProperty(typesEnvPath); - expect(writtenFiles[typesEnvPath]).to.include(`/// <reference path="../.astro/types.d.ts" />`); + assert.equal( + writtenFiles.hasOwnProperty(typesEnvPath), + true, + 'Did not try to update env.d.ts file.' + ); + assert.equal( + writtenFiles[typesEnvPath].includes(`/// <reference path="../.astro/types.d.ts" />`), + true + ); }); it('Writes `src/env.d.ts` if none exists', async () => { @@ -81,8 +90,18 @@ describe('astro sync', () => { }; await fixture.sync({}, { fs: fsMock }); - expect(writtenFiles, 'Did not try to write env.d.ts file.').to.haveOwnProperty(typesEnvPath); - expect(writtenFiles[typesEnvPath]).to.include(`/// <reference types="astro/client" />`); - expect(writtenFiles[typesEnvPath]).to.include(`/// <reference path="../.astro/types.d.ts" />`); + assert.equal( + writtenFiles.hasOwnProperty(typesEnvPath), + true, + 'Did not try to write env.d.ts file.' + ); + assert.equal( + writtenFiles[typesEnvPath].includes(`/// <reference types="astro/client" />`), + true + ); + assert.equal( + writtenFiles[typesEnvPath].includes(`/// <reference path="../.astro/types.d.ts" />`), + true + ); }); }); |