0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2024-12-16 21:46:22 -05:00

improve our smoke tests to run on all examples (#2174)

* improve smoke test

* chore(lint): Prettier fix

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
This commit is contained in:
Fred K. Schott 2021-12-13 14:31:18 -08:00 committed by GitHub
parent bc080288fe
commit a656155629
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 45 additions and 7 deletions

View file

@ -163,11 +163,11 @@ jobs:
run: yarn workspace astro run test
smoke:
name: 'Smoke Test: ${{ matrix.target }}'
runs-on: ubuntu-latest
name: 'Test (Smoke) ${{ matrix.os }}'
runs-on: ${{ matrix.os }}
strategy:
matrix:
target: [docs, www]
os: [windows-latest, ubuntu-latest]
needs:
- build
steps:
@ -177,7 +177,7 @@ jobs:
- name: Setup Node
uses: actions/setup-node@v2
with:
node-version: 16
node-version: 14
cache: 'yarn'
- name: Download Build Artifacts
@ -198,9 +198,15 @@ jobs:
env:
CI: true
- name: Build
run: yarn build
working-directory: ${{ matrix.target }}
- name: Test
if: ${{ matrix.os != 'windows-latest' }}
run: yarn run build:examples --concurrency=1
# Turbo seems to fail on Windows, so run a custom script directly.
- name: Test (Windows)
if: ${{ matrix.os == 'windows-latest' }}
run: node ./scripts/smoke/index.js
# Changelog can only run _after_ Build and Test.
# We download all `dist/` artifacts from GitHub to skip the build process.

View file

@ -9,6 +9,7 @@
"scripts": {
"release": "yarn build && changeset publish",
"build": "turbo run build --no-deps --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"build:examples": "turbo run build --scope=docs --scope=www --scope=\"@example/*\"",
"dev": "turbo run dev --no-deps --no-cache --parallel --scope=astro --scope=create-astro --scope=\"@astrojs/*\"",
"test": "turbo run test --scope=astro",
"test:templates": "turbo run test --scope=create-astro",

31
scripts/smoke/index.js Normal file
View file

@ -0,0 +1,31 @@
import fs from 'fs';
import { execa } from 'execa';
import { fileURLToPath } from 'url';
// NOTE: Only needed for Windows, due to a Turbo bug.
// Once Turbo works on Windows, we can remove this script
// and update our CI to run through Turbo.
export default async function run() {
const examplesUrl = new URL('../../examples/', import.meta.url);
const examplesToTest = fs
.readdirSync(examplesUrl)
.map((filename) => new URL(filename, examplesUrl))
.filter((fileUrl) => fs.statSync(fileUrl).isDirectory());
const allProjectsToTest = [...examplesToTest, new URL('../../www', import.meta.url), new URL('../../docs', import.meta.url)];
console.log('');
for (const projectToTest of allProjectsToTest) {
const filePath = fileURLToPath(projectToTest);
console.log(' 🤖 Testing', filePath, '\n');
try {
await execa('yarn', ['build'], { cwd: fileURLToPath(projectToTest), stdout: 'inherit', stderr: 'inherit' });
} catch (err) {
console.log(err);
process.exit(1);
}
console.log('\n 🤖 Test complete.');
}
}
run();