From 4be3cc8846ad6fca313cb76f14ddd6db3e1e0cd9 Mon Sep 17 00:00:00 2001 From: Benjamin Pasero Date: Fri, 7 Feb 2020 12:41:08 +0100 Subject: [PATCH] test - convert web integration to TS --- .eslintrc.json | 7 + build/npm/postinstall.js | 1 + test/integration/browser/.gitignore | 5 + test/integration/browser/README.md | 13 ++ test/integration/browser/package.json | 17 +++ .../browser/{index.js => src/index.ts} | 66 ++++---- test/integration/browser/tsconfig.json | 21 +++ test/integration/browser/yarn.lock | 143 ++++++++++++++++++ test/smoke/README.md | 2 +- 9 files changed, 241 insertions(+), 34 deletions(-) create mode 100644 test/integration/browser/.gitignore create mode 100644 test/integration/browser/README.md create mode 100644 test/integration/browser/package.json rename test/integration/browser/{index.js => src/index.ts} (62%) create mode 100644 test/integration/browser/tsconfig.json create mode 100644 test/integration/browser/yarn.lock diff --git a/.eslintrc.json b/.eslintrc.json index e7506985bd3..fada4705598 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -614,6 +614,13 @@ "*" ] }, + { + "target": "**/test/integration/**", + "restrictions": [ + "**/test/integration/**", + "*" + ] + }, { "target": "{**/api/**.test.ts,}", "restrictions": "{**/vs/**,assert,sinon,crypto,vscode}" diff --git a/build/npm/postinstall.js b/build/npm/postinstall.js index 83e31e8b853..5a937a80bd8 100644 --- a/build/npm/postinstall.js +++ b/build/npm/postinstall.js @@ -72,4 +72,5 @@ runtime "${runtime}"`; yarnInstall(`build`); // node modules required for build yarnInstall('test/automation'); // node modules required for smoketest yarnInstall('test/smoke'); // node modules required for smoketest +yarnInstall('test/integration/browser'); // node modules required for integration yarnInstallBuildDependencies(); // node modules for watching, specific to host node version, not electron diff --git a/test/integration/browser/.gitignore b/test/integration/browser/.gitignore new file mode 100644 index 00000000000..e7d563c46ad --- /dev/null +++ b/test/integration/browser/.gitignore @@ -0,0 +1,5 @@ +.DS_Store +npm-debug.log +Thumbs.db +node_modules/ +out/ diff --git a/test/integration/browser/README.md b/test/integration/browser/README.md new file mode 100644 index 00000000000..529130a7f7f --- /dev/null +++ b/test/integration/browser/README.md @@ -0,0 +1,13 @@ +# VS Code Integration test + +### Run + +```bash + +# Dev (Electron) +scripts/test-integration.sh + +# Dev (Web) +node test/integration/browser/out/index.js + +``` diff --git a/test/integration/browser/package.json b/test/integration/browser/package.json new file mode 100644 index 00000000000..ed4f447f681 --- /dev/null +++ b/test/integration/browser/package.json @@ -0,0 +1,17 @@ +{ + "name": "code-oss-dev-integration-test", + "version": "0.1.0", + "main": "./index.js", + "scripts": { + "postinstall": "npm run compile", + "compile": "yarn tsc" + }, + "devDependencies": { + "@types/mkdirp": "0.5.1", + "@types/node": "^12.11.7", + "@types/rimraf": "2.0.2", + "rimraf": "^2.6.1", + "tmp": "0.0.33", + "typescript": "3.7.5" + } +} diff --git a/test/integration/browser/index.js b/test/integration/browser/src/index.ts similarity index 62% rename from test/integration/browser/index.js rename to test/integration/browser/src/index.ts index 17508685fcb..11b1e49e73d 100644 --- a/test/integration/browser/index.js +++ b/test/integration/browser/src/index.ts @@ -3,23 +3,19 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ -//@ts-check +import * as path from 'path'; +import * as cp from 'child_process'; +import * as playwright from 'playwright'; +import * as url from 'url'; +import * as tmp from 'tmp'; +import * as rimraf from 'rimraf'; -const path = require('path'); -const cp = require('child_process'); -const playwright = require('playwright'); -const url = require('url'); - -// opts const optimist = require('optimist') .describe('debug', 'do not run browsers headless').boolean('debug') .describe('browser', 'browser in which integration tests should run').string('browser').default('browser', 'chromium') .describe('help', 'show the help').alias('help', 'h'); -// logic -const argv = optimist.argv; - -let serverProcess; +let serverProcess: cp.ChildProcess | undefined = undefined; function teardownServer() { if (serverProcess) { @@ -28,18 +24,17 @@ function teardownServer() { } } -/** - * @param {string} browserType - * @param {string} endpoint - */ -async function runTestsInBrowser(browserType, endpoint) { - const browser = await playwright[browserType].launch({ headless: !Boolean(argv.debug) }); +async function runTestsInBrowser(browserType: string, endpoint: string): Promise { + const browser = await playwright[browserType].launch({ headless: !Boolean(optimist.argv.debug) }); const page = (await browser.defaultContext().pages())[0]; - const integrationTestsPath = path.join(__dirname, '..', '..', '..', 'extensions', 'vscode-api-tests'); - const testWorkspaceUri = url.format({ pathname: path.join(integrationTestsPath, 'testWorkspace'), protocol: 'vscode-remote:', slashes: true, host: 'localhost:9888' }); - const testExtensionUri = url.format({ pathname: path.join(integrationTestsPath), protocol: 'vscode-remote:', slashes: true, host: 'localhost:9888' }); - const testFilesUri = url.format({ pathname: path.join(integrationTestsPath, 'out', 'singlefolder-tests'), protocol: 'vscode-remote:', slashes: true, host: 'localhost:9888' }); + const host = url.parse(endpoint).host; + const protocol = 'vscode-remote'; + + const integrationTestsPath = path.join(__dirname, '..', '..', '..', '..', 'extensions', 'vscode-api-tests'); + const testWorkspaceUri = url.format({ pathname: path.join(integrationTestsPath, 'testWorkspace'), protocol, host, slashes: true }); + const testExtensionUri = url.format({ pathname: path.join(integrationTestsPath), protocol, host, slashes: true }); + const testFilesUri = url.format({ pathname: path.join(integrationTestsPath, 'out', 'singlefolder-tests'), protocol, host, slashes: true }); const folderParam = testWorkspaceUri; const payloadParam = `[["extensionDevelopmentPath","${testExtensionUri}"],["extensionTestsPath","${testFilesUri}"]]`; @@ -51,7 +46,7 @@ async function runTestsInBrowser(browserType, endpoint) { // emitter.emit(type, data1, data2) // }); - page.on('console', async msg => { + page.on('console', async (msg: playwright.ConsoleMessage) => { const msgText = msg.text(); console[msg.type()](msgText, await Promise.all(msg.args().map(async arg => await arg.jsonValue()))); @@ -63,12 +58,15 @@ async function runTestsInBrowser(browserType, endpoint) { }); } -async function launch() { - // workspacePath = _workspacePath; - // const agentFolder = userDataDir; - // await promisify(mkdir)(agentFolder); +async function launchServer(): Promise { + const tmpDir = tmp.dirSync({ prefix: 't' }); + const testDataPath = tmpDir.name; + process.once('exit', () => rimraf.sync(testDataPath)); + + const userDataDir = path.join(testDataPath, 'd'); + const env = { - // VSCODE_AGENT_FOLDER: agentFolder, + VSCODE_AGENT_FOLDER: userDataDir, ...process.env }; @@ -76,7 +74,9 @@ async function launch() { if (process.env.VSCODE_REMOTE_SERVER_PATH) { serverLocation = path.join(process.env.VSCODE_REMOTE_SERVER_PATH, `server.${process.platform === 'win32' ? 'cmd' : 'sh'}`); } else { - serverLocation = path.join(__dirname, '..', '..', '..', `resources/server/web.${process.platform === 'win32' ? 'bat' : 'sh'}`); + serverLocation = path.join(__dirname, '..', '..', '..', '..', `resources/server/web.${process.platform === 'win32' ? 'bat' : 'sh'}`); + + process.env.VSCODE_DEV = '1'; } serverProcess = cp.spawn( @@ -85,15 +85,15 @@ async function launch() { { env } ); - serverProcess.stderr.on('data', e => console.log('Server stderr: ' + e)); - serverProcess.stdout.on('data', e => console.log('Server stdout: ' + e)); + serverProcess?.stderr?.on('data', e => console.log(`Server stderr: ${e}`)); + serverProcess?.stdout?.on('data', e => console.log(`Server stdout: ${e}`)); process.on('exit', teardownServer); process.on('SIGINT', teardownServer); process.on('SIGTERM', teardownServer); return new Promise(r => { - serverProcess.stdout.on('data', d => { + serverProcess?.stdout?.on('data', d => { const matches = d.toString('ascii').match(/Web UI available at (.+)/); if (matches !== null) { r(matches[1]); @@ -102,6 +102,6 @@ async function launch() { }); } -launch().then(async endpoint => { - return runTestsInBrowser(argv.browser, endpoint); +launchServer().then(async endpoint => { + return runTestsInBrowser(optimist.argv.browser, endpoint); }, console.error); diff --git a/test/integration/browser/tsconfig.json b/test/integration/browser/tsconfig.json new file mode 100644 index 00000000000..6f0b40e93e5 --- /dev/null +++ b/test/integration/browser/tsconfig.json @@ -0,0 +1,21 @@ +{ + "compilerOptions": { + "module": "commonjs", + "noImplicitAny": false, + "removeComments": false, + "preserveConstEnums": true, + "target": "es2017", + "strictNullChecks": true, + "noUnusedParameters": false, + "noUnusedLocals": true, + "outDir": "out", + "sourceMap": true, + "lib": [ + "es2016", + "dom" + ] + }, + "exclude": [ + "node_modules" + ] +} diff --git a/test/integration/browser/yarn.lock b/test/integration/browser/yarn.lock new file mode 100644 index 00000000000..059c3c8f3cf --- /dev/null +++ b/test/integration/browser/yarn.lock @@ -0,0 +1,143 @@ +# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY. +# yarn lockfile v1 + + +"@types/events@*": + version "3.0.0" + resolved "https://registry.yarnpkg.com/@types/events/-/events-3.0.0.tgz#2862f3f58a9a7f7c3e78d79f130dd4d71c25c2a7" + integrity sha512-EaObqwIvayI5a8dCzhFrjKzVwKLxjoG9T6Ppd5CEo07LRKfQ8Yokw54r5+Wq7FaBQ+yXRvQAYPrHwya1/UFt9g== + +"@types/glob@*": + version "7.1.1" + resolved "https://registry.yarnpkg.com/@types/glob/-/glob-7.1.1.tgz#aa59a1c6e3fbc421e07ccd31a944c30eba521575" + integrity sha512-1Bh06cbWJUHMC97acuD6UMG29nMt0Aqz1vF3guLfG+kHHJhy3AyohZFFxYk2f7Q1SQIrNwvncxAE0N/9s70F2w== + dependencies: + "@types/events" "*" + "@types/minimatch" "*" + "@types/node" "*" + +"@types/minimatch@*": + version "3.0.3" + resolved "https://registry.yarnpkg.com/@types/minimatch/-/minimatch-3.0.3.tgz#3dca0e3f33b200fc7d1139c0cd96c1268cadfd9d" + integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== + +"@types/mkdirp@0.5.1": + version "0.5.1" + resolved "https://registry.yarnpkg.com/@types/mkdirp/-/mkdirp-0.5.1.tgz#ea887cd024f691c1ca67cce20b7606b053e43b0f" + integrity sha512-XA4vNO6GCBz8Smq0hqSRo4yRWMqr4FPQrWjhJt6nKskzly4/p87SfuJMFYGRyYb6jo2WNIQU2FDBsY5r1BibUA== + dependencies: + "@types/node" "*" + +"@types/node@*": + version "13.7.0" + resolved "https://registry.yarnpkg.com/@types/node/-/node-13.7.0.tgz#b417deda18cf8400f278733499ad5547ed1abec4" + integrity sha512-GnZbirvmqZUzMgkFn70c74OQpTTUcCzlhQliTzYjQMqg+hVKcDnxdL19Ne3UdYzdMA/+W3eb646FWn/ZaT1NfQ== + +"@types/node@^12.11.7": + version "12.12.26" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.26.tgz#213e153babac0ed169d44a6d919501e68f59dea9" + integrity sha512-UmUm94/QZvU5xLcUlNR8hA7Ac+fGpO1EG/a8bcWVz0P0LqtxFmun9Y2bbtuckwGboWJIT70DoWq1r3hb56n3DA== + +"@types/rimraf@2.0.2": + version "2.0.2" + resolved "https://registry.yarnpkg.com/@types/rimraf/-/rimraf-2.0.2.tgz#7f0fc3cf0ff0ad2a99bb723ae1764f30acaf8b6e" + integrity sha512-Hm/bnWq0TCy7jmjeN5bKYij9vw5GrDFWME4IuxV08278NtU/VdGbzsBohcCUJ7+QMqmUq5hpRKB39HeQWJjztQ== + dependencies: + "@types/glob" "*" + "@types/node" "*" + +balanced-match@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/balanced-match/-/balanced-match-1.0.0.tgz#89b4d199ab2bee49de164ea02b89ce462d71b767" + integrity sha1-ibTRmasr7kneFk6gK4nORi1xt2c= + +brace-expansion@^1.1.7: + version "1.1.11" + resolved "https://registry.yarnpkg.com/brace-expansion/-/brace-expansion-1.1.11.tgz#3c7fcbf529d87226f3d2f52b966ff5271eb441dd" + integrity sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA== + dependencies: + balanced-match "^1.0.0" + concat-map "0.0.1" + +concat-map@0.0.1: + version "0.0.1" + resolved "https://registry.yarnpkg.com/concat-map/-/concat-map-0.0.1.tgz#d8a96bd77fd68df7793a73036a3ba0d5405d477b" + integrity sha1-2Klr13/Wjfd5OnMDajug1UBdR3s= + +fs.realpath@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f" + integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8= + +glob@^7.1.3: + version "7.1.6" + resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.6.tgz#141f33b81a7c2492e125594307480c46679278a6" + integrity sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA== + dependencies: + fs.realpath "^1.0.0" + inflight "^1.0.4" + inherits "2" + minimatch "^3.0.4" + once "^1.3.0" + path-is-absolute "^1.0.0" + +inflight@^1.0.4: + version "1.0.6" + resolved "https://registry.yarnpkg.com/inflight/-/inflight-1.0.6.tgz#49bd6331d7d02d0c09bc910a1075ba8165b56df9" + integrity sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk= + dependencies: + once "^1.3.0" + wrappy "1" + +inherits@2: + version "2.0.4" + resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c" + integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ== + +minimatch@^3.0.4: + version "3.0.4" + resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083" + integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA== + dependencies: + brace-expansion "^1.1.7" + +once@^1.3.0: + version "1.4.0" + resolved "https://registry.yarnpkg.com/once/-/once-1.4.0.tgz#583b1aa775961d4b113ac17d9c50baef9dd76bd1" + integrity sha1-WDsap3WWHUsROsF9nFC6753Xa9E= + dependencies: + wrappy "1" + +os-tmpdir@~1.0.2: + version "1.0.2" + resolved "https://registry.yarnpkg.com/os-tmpdir/-/os-tmpdir-1.0.2.tgz#bbe67406c79aa85c5cfec766fe5734555dfa1274" + integrity sha1-u+Z0BseaqFxc/sdm/lc0VV36EnQ= + +path-is-absolute@^1.0.0: + version "1.0.1" + resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f" + integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18= + +rimraf@^2.6.1: + version "2.7.1" + resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.7.1.tgz#35797f13a7fdadc566142c29d4f07ccad483e3ec" + integrity sha512-uWjbaKIK3T1OSVptzX7Nl6PvQ3qAGtKEtVRjRuazjfL3Bx5eI409VZSqgND+4UNnmzLVdPj9FqFJNPqBZFve4w== + dependencies: + glob "^7.1.3" + +tmp@0.0.33: + version "0.0.33" + resolved "https://registry.yarnpkg.com/tmp/-/tmp-0.0.33.tgz#6d34335889768d21b2bcda0aa277ced3b1bfadf9" + integrity sha512-jRCJlojKnZ3addtTOjdIqoRuPEKBvNXcGYqzO6zWZX8KfKEpnGY5jfggJQ3EjKuu8D4bJRr0y+cYJFmYbImXGw== + dependencies: + os-tmpdir "~1.0.2" + +typescript@3.7.5: + version "3.7.5" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.5.tgz#0692e21f65fd4108b9330238aac11dd2e177a1ae" + integrity sha512-/P5lkRXkWHNAbcJIiHPfRoKqyd7bsyCma1hZNUGfn20qm64T6ZBlrzprymeu918H+mB/0rIg2gGK/BXkhhYgBw== + +wrappy@1: + version "1.0.2" + resolved "https://registry.yarnpkg.com/wrappy/-/wrappy-1.0.2.tgz#b5243d8f3ec1aa35f1364605bc0d1036e30ab69f" + integrity sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8= diff --git a/test/smoke/README.md b/test/smoke/README.md index 1060250f7fd..ddd05e7eb65 100644 --- a/test/smoke/README.md +++ b/test/smoke/README.md @@ -1,6 +1,6 @@ # VS Code Smoke Test -Make sure you are on **Node v10.x**. +Make sure you are on **Node v12.x**. ### Run -- GitLab