test-examples.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. const { readdirSync, statSync } = require('fs');
  2. const { join } = require('path');
  3. const execa = require('execa');
  4. const exampleDirs = readdirSync(__dirname)
  5. .map(dir => join(__dirname, dir))
  6. .filter(dir => statSync(dir).isDirectory());
  7. const config = { stdio: 'inherit', shell: true };
  8. // run npm install in parallel
  9. async function install(dir) {
  10. await execa('npm install', { cwd: dir, ...config });
  11. // override the package version of axe-core with the local version.
  12. // this allows the examples to stay examples while allowing us to
  13. // test them against our changes
  14. return await execa('npm install --no-save file:..\\/..\\/..\\/', {
  15. cwd: dir,
  16. ...config
  17. });
  18. }
  19. // run tests synchronously so we can see which one threw an error
  20. function test(dir) {
  21. return execa('npm test', { cwd: dir, ...config });
  22. }
  23. Promise.all(exampleDirs.map(install))
  24. .then(async () => {
  25. for (const dir of exampleDirs) {
  26. await test(dir);
  27. }
  28. // Return successful exit
  29. process.exit();
  30. })
  31. .catch(err => {
  32. console.error(err);
  33. process.exit(1);
  34. });