index.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /** @file Runs all smoke tests and may add extra smoke-test dependencies to `pnpm-lock.yaml`. */
  2. // @ts-check
  3. import { execa } from 'execa';
  4. import { promises as fs } from 'node:fs';
  5. import { fileURLToPath } from 'node:url';
  6. /** URL directory containing the entire project. */
  7. const rootDir = new URL('../../', import.meta.url);
  8. /** URL directory containing the example subdirectories. */
  9. const exampleDir = new URL('examples/', rootDir);
  10. const smokeDir = new URL('smoke/', rootDir);
  11. /** Returns all child directories of the given directory. */
  12. const getChildDirectories = async (/** @type {URL} */ dir) => {
  13. /** @type {URL[]} */
  14. const dirs = [];
  15. for await (const dirent of await fs.opendir(dir)) {
  16. if (dirent.isDirectory()) {
  17. dirs.push(new URL(dirent.name, dir));
  18. }
  19. }
  20. return dirs;
  21. };
  22. /** Runs all smoke tests. */
  23. async function run() {
  24. console.log('');
  25. const directories = [...(await getChildDirectories(smokeDir)), ...(await getChildDirectories(exampleDir))];
  26. console.log('🤖', 'Preparing', 'pnpm');
  27. await execa('pnpm', ['install', '--frozen-lockfile=false'], { cwd: fileURLToPath(rootDir), stdio: 'inherit' });
  28. for (const directory of directories) {
  29. const name = directory.pathname.split('/').at(-1) ?? "";
  30. const isExternal = directory.pathname.includes(smokeDir.pathname);
  31. console.log('🤖', 'Testing', name);
  32. try {
  33. await execa('pnpm', ['install', '--ignore-scripts', '--frozen-lockfile=false'].filter(x => x), { cwd: fileURLToPath(directory), stdio: 'inherit' });
  34. await execa('pnpm', ['astro', 'telemetry', 'disable']);
  35. await execa('pnpm', ['run', 'build'], { cwd: fileURLToPath(directory), stdio: 'inherit' });
  36. } catch (err) {
  37. console.log(err);
  38. process.exit(1);
  39. }
  40. }
  41. }
  42. run();