Skip to content

Commit

Permalink
Refactor test:consumer script to use Mocha for better formatting and …
Browse files Browse the repository at this point in the history
…retries in case of failure (#4793)
  • Loading branch information
sw-joelmut authored Nov 22, 2024
1 parent ff562bc commit ba67046
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 70 deletions.
1 change: 1 addition & 0 deletions testing/consumer-test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tests/generated/*
32 changes: 32 additions & 0 deletions testing/consumer-test/generateTests.ts
Original file line number Diff line number Diff line change
@@ -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("','")}']);
`,
);
}
10 changes: 5 additions & 5 deletions testing/consumer-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"
}
}
65 changes: 0 additions & 65 deletions testing/consumer-test/run.ts

This file was deleted.

5 changes: 5 additions & 0 deletions testing/consumer-test/test.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
20 changes: 20 additions & 0 deletions testing/consumer-test/tests/typescript.js
Original file line number Diff line number Diff line change
@@ -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}`);
});
}
});
};

0 comments on commit ba67046

Please sign in to comment.