Handle flaky tests (#7651)
This commit is contained in:
parent
16af1709a5
commit
d69fe3a8d2
6 changed files with 56 additions and 44 deletions
|
@ -107,8 +107,8 @@
|
||||||
"postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
|
"postbuild": "astro-scripts copy \"src/**/*.astro\" && astro-scripts copy \"src/**/*.wasm\"",
|
||||||
"test:unit": "mocha --exit --timeout 30000 ./test/units/**/*.test.js",
|
"test:unit": "mocha --exit --timeout 30000 ./test/units/**/*.test.js",
|
||||||
"test:unit:match": "mocha --exit --timeout 30000 ./test/units/**/*.test.js -g",
|
"test:unit:match": "mocha --exit --timeout 30000 ./test/units/**/*.test.js -g",
|
||||||
"test": "pnpm run test:unit && mocha --exit --timeout 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
|
"test": "pnpm run test:unit && mocha --exit --timeout 30000 --ignore **/lit-element.test.js && mocha --timeout 30000 **/lit-element.test.js",
|
||||||
"test:match": "mocha --timeout 20000 -g",
|
"test:match": "mocha --timeout 30000 -g",
|
||||||
"test:e2e": "playwright test",
|
"test:e2e": "playwright test",
|
||||||
"test:e2e:match": "playwright test -g"
|
"test:e2e:match": "playwright test -g"
|
||||||
},
|
},
|
||||||
|
|
|
@ -54,7 +54,11 @@ describe('getStaticPaths - dev calls', () => {
|
||||||
await devServer.stop();
|
await devServer.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('only calls getStaticPaths once', async () => {
|
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');
|
let res = await fixture.fetch('/a');
|
||||||
expect(res.status).to.equal(200);
|
expect(res.status).to.equal(200);
|
||||||
|
|
||||||
|
|
|
@ -5,28 +5,29 @@ import * as cheerio from 'cheerio';
|
||||||
describe.skip('Basic app', () => {
|
describe.skip('Basic app', () => {
|
||||||
/** @type {import('./test-utils').Fixture} */
|
/** @type {import('./test-utils').Fixture} */
|
||||||
let fixture;
|
let fixture;
|
||||||
|
/** @type {import('./test-utils').WranglerCLI} */
|
||||||
|
let cli;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/basics/',
|
root: './fixtures/basics/',
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
|
cli = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
|
||||||
|
await cli.ready;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await cli.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('can render', async () => {
|
it('can render', async () => {
|
||||||
const { ready, stop } = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
|
let res = await fetch(`http://localhost:8789/`);
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
try {
|
let html = await res.text();
|
||||||
await ready;
|
let $ = cheerio.load(html);
|
||||||
|
expect($('h1').text()).to.equal('Testing');
|
||||||
let res = await fetch(`http://localhost:8789/`);
|
expect($('#env').text()).to.equal('secret');
|
||||||
expect(res.status).to.equal(200);
|
|
||||||
let html = await res.text();
|
|
||||||
let $ = cheerio.load(html);
|
|
||||||
expect($('h1').text()).to.equal('Testing');
|
|
||||||
expect($('#env').text()).to.equal('secret');
|
|
||||||
} finally {
|
|
||||||
await stop();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -6,6 +6,8 @@ import cloudflare from '../dist/index.js';
|
||||||
describe('Cf metadata and caches', () => {
|
describe('Cf metadata and caches', () => {
|
||||||
/** @type {import('./test-utils').Fixture} */
|
/** @type {import('./test-utils').Fixture} */
|
||||||
let fixture;
|
let fixture;
|
||||||
|
/** @type {import('./test-utils').WranglerCLI} */
|
||||||
|
let cli;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
|
@ -14,22 +16,22 @@ describe('Cf metadata and caches', () => {
|
||||||
adapter: cloudflare(),
|
adapter: cloudflare(),
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
|
cli = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
|
||||||
|
await cli.ready;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await cli.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Load cf and caches API', async () => {
|
it('Load cf and caches API', async () => {
|
||||||
const { ready, stop } = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
|
let res = await fetch(`http://localhost:8788/`);
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
try {
|
let html = await res.text();
|
||||||
await ready;
|
let $ = cheerio.load(html);
|
||||||
let res = await fetch(`http://localhost:8788/`);
|
// console.log($('#cf').text(), html);
|
||||||
expect(res.status).to.equal(200);
|
expect($('#cf').text()).to.contain('city');
|
||||||
let html = await res.text();
|
expect($('#hasCache').text()).to.equal('true');
|
||||||
let $ = cheerio.load(html);
|
|
||||||
// console.log($('#cf').text(), html);
|
|
||||||
expect($('#cf').text()).to.contain('city');
|
|
||||||
expect($('#hasCache').text()).to.equal('true');
|
|
||||||
} finally {
|
|
||||||
await stop();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -5,6 +5,7 @@ import { fileURLToPath } from 'url';
|
||||||
export { fixLineEndings } from '../../../astro/test/test-utils.js';
|
export { fixLineEndings } from '../../../astro/test/test-utils.js';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* @typedef {{ ready: Promise<void>, stop: Promise<void> }} WranglerCLI
|
||||||
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
|
* @typedef {import('../../../astro/test/test-utils').Fixture} Fixture
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -19,6 +20,9 @@ const wranglerPath = fileURLToPath(
|
||||||
new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
|
new URL('../node_modules/wrangler/bin/wrangler.js', import.meta.url)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @returns {WranglerCLI}
|
||||||
|
*/
|
||||||
export function runCLI(basePath, { silent, port = 8787 }) {
|
export function runCLI(basePath, { silent, port = 8787 }) {
|
||||||
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
|
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
|
||||||
const p = spawn('node', [wranglerPath, 'dev', '-l', script, '--port', port]);
|
const p = spawn('node', [wranglerPath, 'dev', '-l', script, '--port', port]);
|
||||||
|
|
|
@ -5,27 +5,28 @@ import * as cheerio from 'cheerio';
|
||||||
describe('With SolidJS', () => {
|
describe('With SolidJS', () => {
|
||||||
/** @type {import('./test-utils').Fixture} */
|
/** @type {import('./test-utils').Fixture} */
|
||||||
let fixture;
|
let fixture;
|
||||||
|
/** @type {import('./test-utils').WranglerCLI} */
|
||||||
|
let cli;
|
||||||
|
|
||||||
before(async () => {
|
before(async () => {
|
||||||
fixture = await loadFixture({
|
fixture = await loadFixture({
|
||||||
root: './fixtures/with-solid-js/',
|
root: './fixtures/with-solid-js/',
|
||||||
});
|
});
|
||||||
await fixture.build();
|
await fixture.build();
|
||||||
|
|
||||||
|
cli = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
|
||||||
|
await cli.ready;
|
||||||
|
});
|
||||||
|
|
||||||
|
after(async () => {
|
||||||
|
await cli.stop();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('renders the solid component', async () => {
|
it('renders the solid component', async () => {
|
||||||
const { ready, stop } = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
|
let res = await fetch(`http://localhost:8790/`);
|
||||||
|
expect(res.status).to.equal(200);
|
||||||
try {
|
let html = await res.text();
|
||||||
await ready;
|
let $ = cheerio.load(html);
|
||||||
|
expect($('.solid').text()).to.equal('Solid Content');
|
||||||
let res = await fetch(`http://localhost:8790/`);
|
|
||||||
expect(res.status).to.equal(200);
|
|
||||||
let html = await res.text();
|
|
||||||
let $ = cheerio.load(html);
|
|
||||||
expect($('.solid').text()).to.equal('Solid Content');
|
|
||||||
} finally {
|
|
||||||
await stop();
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue