aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Bjorn Lu <bjornlu.dev@gmail.com> 2023-07-17 20:30:02 +0800
committerGravatar GitHub <noreply@github.com> 2023-07-17 20:30:02 +0800
commitd69fe3a8d2e1c5d49fe08aa3d974fc37cee9ca93 (patch)
tree68204dbd11dca7d6a70e5139fecff5d05bc33823
parent16af1709a57066a1cce443c1d769e7304ebd4101 (diff)
downloadastro-d69fe3a8d2e1c5d49fe08aa3d974fc37cee9ca93.tar.gz
astro-d69fe3a8d2e1c5d49fe08aa3d974fc37cee9ca93.tar.zst
astro-d69fe3a8d2e1c5d49fe08aa3d974fc37cee9ca93.zip
Handle flaky tests (#7651)
-rw-r--r--packages/astro/package.json4
-rw-r--r--packages/astro/test/astro-get-static-paths.test.js6
-rw-r--r--packages/integrations/cloudflare/test/basics.test.js29
-rw-r--r--packages/integrations/cloudflare/test/cf.test.js30
-rw-r--r--packages/integrations/cloudflare/test/test-utils.js4
-rw-r--r--packages/integrations/cloudflare/test/with-solid-js.test.js27
6 files changed, 56 insertions, 44 deletions
diff --git a/packages/astro/package.json b/packages/astro/package.json
index 15412723b..38fb52098 100644
--- a/packages/astro/package.json
+++ b/packages/astro/package.json
@@ -107,8 +107,8 @@
"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 20000 --ignore **/lit-element.test.js && mocha --timeout 20000 **/lit-element.test.js",
- "test:match": "mocha --timeout 20000 -g",
+ "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 30000 -g",
"test:e2e": "playwright test",
"test:e2e:match": "playwright test -g"
},
diff --git a/packages/astro/test/astro-get-static-paths.test.js b/packages/astro/test/astro-get-static-paths.test.js
index 6294e1926..9ff97831c 100644
--- a/packages/astro/test/astro-get-static-paths.test.js
+++ b/packages/astro/test/astro-get-static-paths.test.js
@@ -54,7 +54,11 @@ describe('getStaticPaths - dev calls', () => {
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');
expect(res.status).to.equal(200);
diff --git a/packages/integrations/cloudflare/test/basics.test.js b/packages/integrations/cloudflare/test/basics.test.js
index d382a9084..b97079b8f 100644
--- a/packages/integrations/cloudflare/test/basics.test.js
+++ b/packages/integrations/cloudflare/test/basics.test.js
@@ -5,28 +5,29 @@ import * as cheerio from 'cheerio';
describe.skip('Basic app', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
root: './fixtures/basics/',
});
await fixture.build();
- });
- it('can render', async () => {
- const { ready, stop } = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
+ cli = runCLI('./fixtures/basics/', { silent: true, port: 8789 });
+ await cli.ready;
+ });
- try {
- await ready;
+ after(async () => {
+ await cli.stop();
+ });
- let res = await fetch(`http://localhost:8789/`);
- 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();
- }
+ it('can render', async () => {
+ let res = await fetch(`http://localhost:8789/`);
+ 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');
});
});
diff --git a/packages/integrations/cloudflare/test/cf.test.js b/packages/integrations/cloudflare/test/cf.test.js
index cf310f34d..559df5c76 100644
--- a/packages/integrations/cloudflare/test/cf.test.js
+++ b/packages/integrations/cloudflare/test/cf.test.js
@@ -6,6 +6,8 @@ import cloudflare from '../dist/index.js';
describe('Cf metadata and caches', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
@@ -14,22 +16,22 @@ describe('Cf metadata and caches', () => {
adapter: cloudflare(),
});
await fixture.build();
+
+ cli = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
+ await cli.ready;
});
- it('Load cf and caches API', async () => {
- const { ready, stop } = runCLI('./fixtures/cf/', { silent: true, port: 8788 });
+ after(async () => {
+ await cli.stop();
+ });
- try {
- await ready;
- let res = await fetch(`http://localhost:8788/`);
- expect(res.status).to.equal(200);
- let html = await res.text();
- let $ = cheerio.load(html);
- // console.log($('#cf').text(), html);
- expect($('#cf').text()).to.contain('city');
- expect($('#hasCache').text()).to.equal('true');
- } finally {
- await stop();
- }
+ it('Load cf and caches API', async () => {
+ let res = await fetch(`http://localhost:8788/`);
+ expect(res.status).to.equal(200);
+ let html = await res.text();
+ let $ = cheerio.load(html);
+ // console.log($('#cf').text(), html);
+ expect($('#cf').text()).to.contain('city');
+ expect($('#hasCache').text()).to.equal('true');
});
});
diff --git a/packages/integrations/cloudflare/test/test-utils.js b/packages/integrations/cloudflare/test/test-utils.js
index e0fc90a64..bff7fb2a4 100644
--- a/packages/integrations/cloudflare/test/test-utils.js
+++ b/packages/integrations/cloudflare/test/test-utils.js
@@ -5,6 +5,7 @@ import { fileURLToPath } from 'url';
export { fixLineEndings } from '../../../astro/test/test-utils.js';
/**
+ * @typedef {{ ready: Promise<void>, stop: Promise<void> }} WranglerCLI
* @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)
);
+/**
+ * @returns {WranglerCLI}
+ */
export function runCLI(basePath, { silent, port = 8787 }) {
const script = fileURLToPath(new URL(`${basePath}/dist/_worker.js`, import.meta.url));
const p = spawn('node', [wranglerPath, 'dev', '-l', script, '--port', port]);
diff --git a/packages/integrations/cloudflare/test/with-solid-js.test.js b/packages/integrations/cloudflare/test/with-solid-js.test.js
index 270c387b5..90c1c0722 100644
--- a/packages/integrations/cloudflare/test/with-solid-js.test.js
+++ b/packages/integrations/cloudflare/test/with-solid-js.test.js
@@ -5,27 +5,28 @@ import * as cheerio from 'cheerio';
describe('With SolidJS', () => {
/** @type {import('./test-utils').Fixture} */
let fixture;
+ /** @type {import('./test-utils').WranglerCLI} */
+ let cli;
before(async () => {
fixture = await loadFixture({
root: './fixtures/with-solid-js/',
});
await fixture.build();
- });
- it('renders the solid component', async () => {
- const { ready, stop } = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
+ cli = runCLI('./fixtures/with-solid-js/', { silent: true, port: 8790 });
+ await cli.ready;
+ });
- try {
- await ready;
+ after(async () => {
+ await cli.stop();
+ });
- 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();
- }
+ it('renders the solid component', async () => {
+ 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');
});
});