launcher.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import * as jestCLI from 'jest-cli';
  2. import { TestResultsInfo } from '../types';
  3. import fs from 'fs';
  4. export async function runEndToEndTests(outputDirectory: string, results: TestResultsInfo): Promise<void> {
  5. const setupPath = 'node_modules/@grafana/toolkit/src/e2e/install';
  6. let ext = '.js';
  7. if (!fs.existsSync(setupPath + ext)) {
  8. ext = '.ts'; // When running yarn link
  9. }
  10. const jestConfig = {
  11. preset: 'ts-jest',
  12. verbose: false,
  13. moduleDirectories: ['node_modules'], // add the plugin somehow?
  14. moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json'],
  15. setupFiles: [],
  16. setupFilesAfterEnv: [
  17. 'expect-puppeteer', // Setup Puppeteer
  18. '<rootDir>/' + setupPath + ext, // Loads Chromimum
  19. ],
  20. globals: { 'ts-jest': { isolatedModules: true } },
  21. testMatch: [
  22. '<rootDir>/e2e-temp/**/*.test.ts', // Copied from node_modules
  23. '<rootDir>/e2e/test/**/*.test.ts',
  24. ],
  25. reporters: [
  26. 'default',
  27. ['jest-junit', { outputDirectory }], // save junit.xml to folder
  28. ],
  29. };
  30. const cliConfig = {
  31. config: JSON.stringify(jestConfig),
  32. passWithNoTests: true,
  33. };
  34. // @ts-ignore
  35. const runJest = () => jestCLI.runCLI(cliConfig, [process.cwd()]);
  36. const jestOutput = await runJest();
  37. results.passed = jestOutput.results.numPassedTests;
  38. results.failed = jestOutput.results.numFailedTestSuites;
  39. return;
  40. }