Replace mocha with tape (for security issue)

This commit is contained in:
Alex Dima 2020-03-16 16:38:43 +01:00
parent e47349321a
commit f697f2e5ba
No known key found for this signature in database
GPG key ID: 6E58D7B045760DA0
7 changed files with 154 additions and 695 deletions

View file

@ -1,5 +0,0 @@
{
"delay": true,
"ui": "tdd",
"spec": "test/all.js"
}

View file

@ -8,6 +8,5 @@
/tsconfig.json /tsconfig.json
/.npmignore /.npmignore
/.travis.yml /.travis.yml
/.mocharc.json
/.editorconfig /.editorconfig
/azure-pipelines.yml /azure-pipelines.yml

4
.vscode/launch.json vendored
View file

@ -5,9 +5,11 @@
"name": "Unit Tests", "name": "Unit Tests",
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "program": "${workspaceRoot}/node_modules/.bin/tape",
"stopOnEntry": false, "stopOnEntry": false,
"args": [ "args": [
"-r",
"./test/all.js",
// "--grep", // "--grep",
// "typescript" // "typescript"
], ],

802
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -5,7 +5,8 @@
"scripts": { "scripts": {
"compile": "mrmdir ./release && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json", "compile": "mrmdir ./release && tsc -p ./src/tsconfig.json && tsc -p ./src/tsconfig.esm.json",
"watch": "tsc -p ./src --watch", "watch": "tsc -p ./src --watch",
"test": "mocha", "watch-esm": "tsc -p ./src/tsconfig.esm.json --watch",
"test": "tape -r ./test/all.js",
"prepublishOnly": "npm run compile && node ./scripts/bundle" "prepublishOnly": "npm run compile && node ./scripts/bundle"
}, },
"author": "Microsoft Corporation", "author": "Microsoft Corporation",
@ -18,12 +19,13 @@
"url": "https://github.com/Microsoft/monaco-languages/issues" "url": "https://github.com/Microsoft/monaco-languages/issues"
}, },
"devDependencies": { "devDependencies": {
"@types/tape": "^4.2.34",
"glob": "^7.1.6", "glob": "^7.1.6",
"jsdom": "^16.2.1", "jsdom": "^16.2.1",
"mocha": "^7.1.0",
"monaco-editor-core": "0.20.0", "monaco-editor-core": "0.20.0",
"monaco-plugin-helpers": "^1.0.2", "monaco-plugin-helpers": "^1.0.2",
"requirejs": "^2.3.6", "requirejs": "^2.3.6",
"tape": "^4.13.2",
"terser": "^4.6.6", "terser": "^4.6.6",
"typescript": "3.7.5" "typescript": "3.7.5"
} }

View file

@ -5,7 +5,7 @@
import '../monaco.contribution'; import '../monaco.contribution';
import {loadLanguage} from '../_.contribution'; import {loadLanguage} from '../_.contribution';
import * as assert from 'assert'; import * as test from 'tape';
// Allow for running under nodejs/requirejs in tests // Allow for running under nodejs/requirejs in tests
const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco); const _monaco: typeof monaco = (typeof monaco === 'undefined' ? (<any>self).monaco : monaco);
@ -28,24 +28,23 @@ export function testTokenization(_language:string|string[], tests:ITestItem[][])
languages = _language; languages = _language;
} }
let mainLanguage = languages[0]; let mainLanguage = languages[0];
suite(mainLanguage + ' tokenization', () => {
test('', (done) => { test(mainLanguage + ' tokenization', (t: test.Test) => {
Promise.all(languages.map(l => loadLanguage(l))).then(() => { Promise.all(languages.map(l => loadLanguage(l))).then(() => {
// clean stack // clean stack
setTimeout(() => { setTimeout(() => {
runTests(mainLanguage, tests); runTests(t, mainLanguage, tests);
done(); t.end();
}); });
}).then(null, done); }).then(null, () => t.end());
});
}); });
} }
function runTests(languageId:string, tests:ITestItem[][]): void { function runTests(t: test.Test, languageId:string, tests:ITestItem[][]): void {
tests.forEach((test) => runTest(languageId, test)); tests.forEach((test) => runTest(t, languageId, test));
} }
function runTest(languageId:string, test:ITestItem[]): void { function runTest(t: test.Test, languageId:string, test:ITestItem[]): void {
let text = test.map(t => t.line).join('\n'); let text = test.map(t => t.line).join('\n');
let actualTokens = _monaco.editor.tokenize(text, languageId); let actualTokens = _monaco.editor.tokenize(text, languageId);
@ -61,5 +60,5 @@ function runTest(languageId:string, test:ITestItem[]): void {
}; };
}); });
assert.deepEqual(actual, test); t.deepEqual(actual, test);
} }

View file

@ -27,7 +27,7 @@ requirejs(['./test/setup'], function () {
return; return;
} }
requirejs(files.map(f => f.replace(/\.js$/, '')), function () { requirejs(files.map(f => f.replace(/\.js$/, '')), function () {
run(); // We can launch the tests! // We can launch the tests!
}, function (err) { }, function (err) {
console.log(err); console.log(err);
}) })