microsoft/vscode-react-native
Publicmirrored fromhttps://github.com/microsoft/vscode-react-nativeAvailable
gulp_scripts/tester.js
73lines · modecode
| 1 | const gulp = require("gulp"); |
| 2 | const log = require("fancy-log"); |
| 3 | const minimist = require("minimist"); |
| 4 | const path = require("path"); |
| 5 | const vscodeTest = require("@vscode/test-electron"); |
| 6 | const getBuilder = require("./builder"); |
| 7 | const getFormatter = require("./formatter"); |
| 8 | |
| 9 | const vscodeVersionForTests = "stable"; |
| 10 | |
| 11 | const knownOptions = { |
| 12 | string: "env", |
| 13 | default: { env: "production" }, |
| 14 | }; |
| 15 | const options = minimist(process.argv.slice(2), knownOptions); |
| 16 | |
| 17 | async function test(inspectCodeCoverage = false) { |
| 18 | // Check if arguments were passed |
| 19 | // if (options.pattern) { |
| 20 | // log(`\nTesting cases that match pattern: ${options.pattern}`); |
| 21 | // } else { |
| 22 | // log(`\nTesting cases that don't match pattern: extensionContext|localizationContext`); |
| 23 | // } |
| 24 | |
| 25 | if (options != null) { |
| 26 | log(`\nArgument passed.`); |
| 27 | } else { |
| 28 | log(`\nArgument not passed.`); |
| 29 | } |
| 30 | |
| 31 | try { |
| 32 | // The folder containing the Extension Manifest package.json |
| 33 | // Passed to `--extensionDevelopmentPath` |
| 34 | const extensionDevelopmentPath = __dirname; |
| 35 | |
| 36 | // The path to the extension test runner script |
| 37 | // Passed to --extensionTestsPath |
| 38 | const extensionTestsPath = path.resolve(__dirname, "test", "index"); |
| 39 | console.log(extensionTestsPath); |
| 40 | // Download VS Code, unzip it and run the integration test |
| 41 | |
| 42 | const testOptions = { |
| 43 | extensionDevelopmentPath, |
| 44 | extensionTestsPath, |
| 45 | version: vscodeVersionForTests, |
| 46 | }; |
| 47 | |
| 48 | // Activate inspection of code coverage with unit tests |
| 49 | if (inspectCodeCoverage) { |
| 50 | testOptions.extensionTestsEnv = { |
| 51 | COVERAGE: "true", |
| 52 | }; |
| 53 | } |
| 54 | |
| 55 | await vscodeTest.runTests(testOptions); |
| 56 | } catch (err) { |
| 57 | console.error(err); |
| 58 | console.error("Failed to run tests"); |
| 59 | process.exit(1); |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | const testTask = gulp.series(getBuilder.buildTask, getFormatter.lint, test); |
| 64 | |
| 65 | const testCoverage = gulp.series(gulp.series(getBuilder.buildDev), async function () { |
| 66 | await test(true); |
| 67 | }); |
| 68 | |
| 69 | module.exports = { |
| 70 | test, |
| 71 | testTask, |
| 72 | testCoverage, |
| 73 | }; |
| 74 | |