Skip to content

Commit 8309334

Browse files
committed
web tests
1 parent 80cc7eb commit 8309334

File tree

10 files changed

+34
-19
lines changed

10 files changed

+34
-19
lines changed

packages/amazonq/.vscode/launch.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,11 +108,11 @@
108108
"--disable-extension=amazonwebservices.aws-toolkit-vscode",
109109
"--extensionDevelopmentPath=${workspaceFolder}",
110110
"--extensionDevelopmentKind=web",
111-
"--extensionTestsPath=${workspaceFolder}/dist/test/web/index",
112-
"${workspaceRoot}/dist/src/testFixtures/workspaceFolder"
111+
"--extensionTestsPath=${workspaceFolder}/dist/test/web/testRunnerWebCore",
112+
"${workspaceFolder}/../core/dist/src/testFixtures/workspaceFolder"
113113
],
114114
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],
115-
"preLaunchTask": "testsBuildWatch",
115+
"preLaunchTask": "webRun",
116116
"presentation": {
117117
"group": "3_ExtensionTests",
118118
"order": 3

packages/amazonq/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@
5252
"syncPackageJson": "ts-node ./scripts/build/syncPackageJson.ts",
5353
"clean": "ts-node ../../scripts/clean.ts dist/ LICENSE NOTICE",
5454
"compile": "npm run clean && npm run buildScripts && webpack",
55-
"compileDev": "npm run compile -- --mode development",
55+
"compileDev": "npm run testCompile && webpack --mode development",
5656
"compileOnly": "tsc -p ./",
5757
"package": "ts-node ../../scripts/package.ts",
5858
"lint": "true",
5959
"watch": "npm run clean && npm run buildScripts && tsc -watch -p ./",
6060
"testCompile": "npm run clean && npm run buildScripts && npm run compileOnly",
6161
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts unit dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
6262
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts e2e dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
63-
"testWeb": "npm run compileDev && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts web dist/src/extensionWebTest.js ../core/dist/src/testFixtures/workspaceFolder",
63+
"testWeb": "npm run compileDev && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts web dist/test/web/testRunnerWebCore.js",
6464
"webRun": "npx @vscode/test-web --open-devtools --browserOption=--disable-web-security --waitForDebugger=9222 --extensionDevelopmentPath=. .",
6565
"webWatch": "npm run clean && npm run buildScripts && webpack --mode development --watch",
6666
"serve": "webpack serve --config-name mainServe --mode development",

packages/amazonq/test/web/extension.test.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,15 @@
44
*/
55

66
import assert from 'assert'
7-
import globals, { ToolkitGlobals } from 'aws-core-vscode/shared'
7+
import { ToolkitGlobals } from 'aws-core-vscode/shared'
88

99
describe('activation', async () => {
1010
it('defines a region provider that can provide regions when in web mode', async () => {
11+
// For some reason, a top-level import will result in undefined.
12+
// Other tests don't seem to have this issue.
13+
// TODO: why?
14+
const { globals } = require('aws-core-vscode/shared')
15+
1116
assert((globals as unknown as ToolkitGlobals).regionProvider.getRegions().length > 0)
1217
})
1318
})

packages/amazonq/test/web/shared/utilities/timeoutUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@
99
*
1010
* Any web specific tests should be made within their own `describe()`.
1111
*/
12-
import { timeoutUtilsDescribe } from 'aws-core-vscode/test'
12+
import { timeoutUtilsDescribe } from 'aws-core-vscode/testWeb'
1313
timeoutUtilsDescribe

packages/amazonq/test/web/testRunner.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'mocha' // Imports mocha for the browser, defining the `mocha` global.
1212
import * as vscode from 'vscode'
1313

1414
export async function run(): Promise<void> {
15-
await activateToolkitExtension()
15+
await activateExtension()
1616
return new Promise(async (resolve, reject) => {
1717
setupMocha()
1818
gatherTestFiles()
@@ -45,7 +45,12 @@ function gatherTestFiles() {
4545
*
4646
* So this function ensures the extension has fully activated.
4747
*/
48-
async function activateToolkitExtension() {
48+
async function activateExtension() {
49+
const extId = VSCODE_EXTENSION_ID.amazonq
50+
const ext = vscode.extensions.getExtension(extId)
51+
if (!ext) {
52+
throw new Error(`Extension '${extId}' not found, can't activate it to run tests.`)
53+
}
4954
await vscode.extensions.getExtension(VSCODE_EXTENSION_ID.amazonq)?.activate()
5055
}
5156

packages/amazonq/webpack.config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ module.exports = (env, argv) => {
1818
...baseWebConfigsFactory(env, argv),
1919
entry: {
2020
'src/extensionWeb': './src/extensionWeb.ts',
21-
'src/extensionWebTest': './test/web/testRunner.ts',
21+
'test/web/testRunnerWebCore': './test/web/testRunner.ts',
2222
},
2323
}
2424

packages/core/.vscode/tasks.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,6 @@
2222
"isBackground": true,
2323
"problemMatcher": "$ts-webpack-watch"
2424
},
25-
{
26-
"label": "testsBuildWatch",
27-
"command": "npm run compileDev -- --watch",
28-
"detail": "Build that is sufficient for Web mode tests",
29-
"type": "shell",
30-
"isBackground": true,
31-
"problemMatcher": "$ts-webpack-watch"
32-
},
3325
/**
3426
After we stop debugging our browser, we also want to stop the web server.
3527
When this task is ran it will stop the web server.

packages/core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"./amazonqFeatureDev": "./dist/src/amazonqFeatureDev/index.js",
4242
"./codewhispererChat": "./dist/src/codewhispererChat/index.js",
4343
"./test": "./dist/src/test/index.js",
44+
"./testWeb": "./dist/src/testWeb/index.js",
4445
"./login": "./dist/src/login/webview/index.js",
4546
"./utils": "./dist/src/shared/utilities/index.js",
4647
"./feedback": "./dist/src/feedback/index.js",

packages/core/src/test/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

6+
/**
7+
* Some imports in this file are node compatible only.
8+
* For web-based test imports, see {@link file://./../testWeb/index.ts}
9+
*/
10+
611
export { registerAuthHook, using } from './setupUtil'
712
export { runTests } from './testRunner'
813
export { MockDocument } from './fake/fakeDocument'
@@ -14,7 +19,6 @@ export { getTestLogger } from './globalSetup.test'
1419
export { testCommand } from './shared/vscode/testUtils'
1520
export { FakeAwsContext } from './utilities/fakeAwsContext'
1621
export { getTestWorkspaceFolder } from '../testInteg/integrationTestsUtilities'
17-
export { timeoutUtilsDescribe } from './shared/utilities/timeoutUtils.test'
1822
export * from './codewhisperer/testUtil'
1923
export * from './credentials/testUtil'
2024
export * from './testUtil'

packages/core/src/testWeb/index.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/** Web-compatible tests and test utilities. */
7+
8+
export { timeoutUtilsDescribe } from '../test/shared/utilities/timeoutUtils.test'

0 commit comments

Comments
 (0)