Skip to content

Commit 80cc7eb

Browse files
committed
wip
1 parent e60b2e9 commit 80cc7eb

File tree

19 files changed

+189
-168
lines changed

19 files changed

+189
-168
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"type": "Bug Fix",
3+
"description": "Auth: 'Start using Amazon Q' notification being displayed even if signed in."
4+
}

packages/amazonq/.vscode/launch.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,25 @@
9999
"order": 2
100100
}
101101
},
102+
{
103+
"name": "Extension Tests (web)",
104+
"type": "extensionHost",
105+
"debugWebWorkerHost": true,
106+
"request": "launch",
107+
"args": [
108+
"--disable-extension=amazonwebservices.aws-toolkit-vscode",
109+
"--extensionDevelopmentPath=${workspaceFolder}",
110+
"--extensionDevelopmentKind=web",
111+
"--extensionTestsPath=${workspaceFolder}/dist/test/web/index",
112+
"${workspaceRoot}/dist/src/testFixtures/workspaceFolder"
113+
],
114+
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],
115+
"preLaunchTask": "testsBuildWatch",
116+
"presentation": {
117+
"group": "3_ExtensionTests",
118+
"order": 3
119+
}
120+
},
102121
{
103122
"name": "E2E Test (current file)",
104123
"type": "extensionHost",

packages/amazonq/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,16 @@
5151
"copyFiles": "ts-node ./scripts/build/copyFiles.ts",
5252
"syncPackageJson": "ts-node ./scripts/build/syncPackageJson.ts",
5353
"clean": "ts-node ../../scripts/clean.ts dist/ LICENSE NOTICE",
54-
"compile": "npm run clean && npm run buildScripts && webpack --mode development",
54+
"compile": "npm run clean && npm run buildScripts && webpack",
55+
"compileDev": "npm run compile -- --mode development",
5556
"compileOnly": "tsc -p ./",
5657
"package": "ts-node ../../scripts/package.ts",
5758
"lint": "true",
5859
"watch": "npm run clean && npm run buildScripts && tsc -watch -p ./",
5960
"testCompile": "npm run clean && npm run buildScripts && npm run compileOnly",
6061
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts unit dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
6162
"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",
6264
"webRun": "npx @vscode/test-web --open-devtools --browserOption=--disable-web-security --waitForDebugger=9222 --extensionDevelopmentPath=. .",
6365
"webWatch": "npm run clean && npm run buildScripts && webpack --mode development --watch",
6466
"serve": "webpack serve --config-name mainServe --mode development",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import globals, { ToolkitGlobals } from 'aws-core-vscode/shared'
8+
9+
describe('activation', async () => {
10+
it('defines a region provider that can provide regions when in web mode', async () => {
11+
assert((globals as unknown as ToolkitGlobals).regionProvider.getRegions().length > 0)
12+
})
13+
})
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import { randomUUID } from 'aws-core-vscode/shared'
8+
9+
describe('crypto', function () {
10+
describe('randomUUID()', function () {
11+
const uuidPattern = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i
12+
13+
it('functions as normal', async function () {
14+
const result1 = randomUUID()
15+
const result2 = randomUUID()
16+
const result3 = randomUUID()
17+
assert(uuidPattern.test(result1))
18+
assert(uuidPattern.test(result2))
19+
assert(uuidPattern.test(result3))
20+
assert(result1 !== result2)
21+
assert(result2 !== result3)
22+
})
23+
24+
it('test pattern fails on non-uuid', function () {
25+
assert(uuidPattern.test('not-a-uuid') === false)
26+
})
27+
})
28+
})
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import assert from 'assert'
7+
import { fs, globals } from 'aws-core-vscode/shared'
8+
9+
describe('FileSystem', function () {
10+
it('getUserHomeDir()', async () => {
11+
// TODO: testWeb needs a `globalSetup.test.ts` ...
12+
await fs.init(globals.context, () => undefined)
13+
assert.strictEqual(fs.getUserHomeDir(), globals.context.globalStorageUri.toString())
14+
})
15+
16+
it('getUsername()', async () => {
17+
// TODO: testWeb needs a `globalSetup.test.ts` ...
18+
await fs.init(globals.context, () => undefined)
19+
assert.strictEqual(fs.getUsername(), 'webuser')
20+
})
21+
})
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* IMPORTANT: We are importing the same test from the node timeoutUtils
8+
* since the behavior should be the exact same.
9+
*
10+
* Any web specific tests should be made within their own `describe()`.
11+
*/
12+
import { timeoutUtilsDescribe } from 'aws-core-vscode/test'
13+
timeoutUtilsDescribe
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
/**
7+
* The following was influenced by this guide: https://code.visualstudio.com/api/extension-guides/web-extensions
8+
*/
9+
10+
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
11+
import 'mocha' // Imports mocha for the browser, defining the `mocha` global.
12+
import * as vscode from 'vscode'
13+
14+
export async function run(): Promise<void> {
15+
await activateToolkitExtension()
16+
return new Promise(async (resolve, reject) => {
17+
setupMocha()
18+
gatherTestFiles()
19+
20+
try {
21+
runMochaTests(resolve, reject)
22+
} catch (err) {
23+
console.error(err)
24+
reject(err)
25+
}
26+
})
27+
}
28+
29+
function setupMocha() {
30+
mocha.setup({
31+
ui: 'bdd',
32+
reporter: undefined,
33+
})
34+
}
35+
36+
function gatherTestFiles() {
37+
// Bundles all files in the current directory matching `*.test`
38+
const importAll = (r: __WebpackModuleApi.RequireContext) => r.keys().forEach(r)
39+
importAll(require.context('.', true, /\.test$/))
40+
}
41+
42+
/**
43+
* Typically extensions activate depending on their configuration in `package.json#activationEvents`, but in tests
44+
* there is a race condition for when the extension has finished activating and when we start the tests.
45+
*
46+
* So this function ensures the extension has fully activated.
47+
*/
48+
async function activateToolkitExtension() {
49+
await vscode.extensions.getExtension(VSCODE_EXTENSION_ID.amazonq)?.activate()
50+
}
51+
52+
function runMochaTests(resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void) {
53+
mocha.run((failures) => {
54+
if (failures > 0) {
55+
reject(new Error(`${failures} tests failed.`))
56+
} else {
57+
resolve()
58+
}
59+
})
60+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*!
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
*/
5+
6+
import * as assert from 'assert'
7+
import { isWeb } from 'aws-core-vscode/shared'
8+
9+
describe('isWeb', function () {
10+
it('returns true when in web mode', function () {
11+
// Note that this only works since the state is indirectly stored in `globalThis`, see web.md for more info
12+
assert.strictEqual(isWeb(), true)
13+
})
14+
})

packages/amazonq/webpack.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +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',
2122
},
2223
}
2324

0 commit comments

Comments
 (0)