Refactor test:consumer script to use Mocha for better formatting and retries in case of failure
This commit is contained in:
Родитель
dccf5896c9
Коммит
db8cca5b46
|
@ -0,0 +1 @@
|
|||
tests/generated/*
|
|
@ -0,0 +1,32 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This script generates test files for each version of TypeScript, so the test can run in parallel.
|
||||
*/
|
||||
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
const versions = ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6'];
|
||||
const targets = ['es6', 'esnext'];
|
||||
|
||||
const testsDir = path.resolve(__dirname, 'tests/generated');
|
||||
|
||||
if (fs.existsSync(testsDir)) {
|
||||
fs.rmSync(testsDir, { recursive: true });
|
||||
}
|
||||
|
||||
fs.mkdirSync(testsDir);
|
||||
|
||||
for (const version of versions) {
|
||||
fs.writeFileSync(
|
||||
path.resolve(testsDir, `typescript.${version}.test.js`),
|
||||
`
|
||||
const testVersion = require('../typescript');
|
||||
testVersion('${version}', ['${targets.join("','")}']);
|
||||
`,
|
||||
);
|
||||
}
|
|
@ -4,7 +4,9 @@
|
|||
"version": "1.0.0",
|
||||
"scripts": {
|
||||
"lint": "eslint .",
|
||||
"test": "ts-node run.ts --verbose"
|
||||
"test": "npm-run-all test:gen test:mocha",
|
||||
"test:gen": "ts-node ./generateTests.ts",
|
||||
"test:mocha": "mocha ./tests/generated/*.test.js --parallel"
|
||||
},
|
||||
"dependencies": {
|
||||
"adaptive-expressions": "4.1.6",
|
||||
|
@ -35,11 +37,9 @@
|
|||
"botframework-connector": "4.1.6",
|
||||
"botframework-schema": "4.1.6",
|
||||
"botframework-streaming": "4.1.6",
|
||||
"eslint-plugin-only-warn": "^1.1.0",
|
||||
"minimist": "^1.2.6",
|
||||
"p-map": "^4.0.0"
|
||||
"eslint-plugin-only-warn": "^1.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/minimist": "^1.2.5"
|
||||
"mocha": "^10.7.3"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
import minimist from 'minimist';
|
||||
import pmap from 'p-map';
|
||||
import { exec } from 'child_process';
|
||||
import { promisify } from 'util';
|
||||
|
||||
const execp = promisify(exec);
|
||||
|
||||
const versions = ['4.7', '4.8', '4.9', '5.0', '5.1', '5.2', '5.3', '5.4', '5.5', '5.6'];
|
||||
|
||||
(async () => {
|
||||
const flags = minimist(process.argv.slice(2), {
|
||||
boolean: ['verbose'],
|
||||
alias: { v: 'verbose' },
|
||||
});
|
||||
|
||||
try {
|
||||
const [minTarget, maxTarget] = ['es6', 'esnext'];
|
||||
console.log(
|
||||
`Running typescript consumer test against ["${versions.join(
|
||||
'", "'
|
||||
)}"] with '${minTarget}' and '${maxTarget}' targets.`
|
||||
);
|
||||
|
||||
const results = await pmap(
|
||||
versions,
|
||||
(version) =>
|
||||
Promise.all([
|
||||
execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --target ${minTarget}`),
|
||||
execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --target ${maxTarget}`),
|
||||
])
|
||||
.then(() => ({ err: null, version, success: true }))
|
||||
.catch((err) => ({ err, version, success: false })),
|
||||
{ concurrency: 2 }
|
||||
);
|
||||
|
||||
const initialValue: { success: string[]; failed: string[] } = {
|
||||
success: [],
|
||||
failed: [],
|
||||
};
|
||||
|
||||
const { success, failed } = results.reduce((acc, result) => {
|
||||
if (result.success) {
|
||||
acc.success.push(result.version);
|
||||
} else {
|
||||
acc.failed.push(result.version);
|
||||
}
|
||||
|
||||
return acc;
|
||||
}, initialValue);
|
||||
|
||||
console.log('Success:', success);
|
||||
console.log('Failed:', failed);
|
||||
|
||||
if (flags.verbose) {
|
||||
results
|
||||
.filter(({ success }) => success === false)
|
||||
.forEach(({ err, version }) => console.error(`typescript@${version}`, err));
|
||||
}
|
||||
|
||||
process.exit(failed.length ? 1 : 0);
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
process.exit(-1);
|
||||
}
|
||||
})();
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
import * as adaptiveExpressions from 'adaptive-expressions';
|
||||
import * as adaptiveExpressionsIE11 from 'adaptive-expressions-ie11';
|
||||
import * as botbuilder from 'botbuilder';
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
/**
|
||||
* Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
* Licensed under the MIT License.
|
||||
*/
|
||||
|
||||
const { exec } = require('child_process');
|
||||
const { promisify } = require('util');
|
||||
const execp = promisify(exec);
|
||||
|
||||
module.exports = function testVersion(version, targets) {
|
||||
describe(`typescript:${version}`, function () {
|
||||
this.timeout(300000); // 5 minutes
|
||||
this.retries(1);
|
||||
for (const target of targets) {
|
||||
it(`target:${target}`, async function () {
|
||||
await execp(`npx -p typescript@${version} tsc -p tsconfig-test.json --target ${target}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
};
|
Загрузка…
Ссылка в новой задаче