Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion buildspec/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ phases:
build:
commands:
- export HOME=/home/codebuild-user
- npm run testCompile
- npm run compile -w packages/core
- npm run testCompile -w packages/ --if-present
- npm run lint
- VCS_COMMIT_ID="${CODEBUILD_RESOLVED_SOURCE_VERSION}"
- CI_BUILD_URL=$(echo $CODEBUILD_BUILD_URL | sed 's/#/%23/g') # Encode `#` in the URL because otherwise the url is clipped in the Codecov.io site
Expand Down
3 changes: 2 additions & 1 deletion buildspec/windowsTests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ phases:

build:
commands:
- npm run testCompile
- npm run compile -w packages/core
- npm run testCompile -w packages/ --if-present
- npm run lint
- $env:TEST_REPORT_DIR="$env:CODEBUILD_SRC_DIR/.test_reports"; npm run test
- |
Expand Down
5 changes: 3 additions & 2 deletions docs/TESTPLAN.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ The test suite has the following categories of tests:

## Test files

Currently, most if not all testing code lives in the subproject `packages/core/`.
For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure)
Currently, most testing code lives in the subproject `packages/core/` due to the move to monorepo. See [arch_develop.md](./arch_develop.md#monorepo-structure).

- `src/test/` : unit tests
- `src/test/globalSetup.test.ts` :
Expand All @@ -60,6 +59,8 @@ For more information, see [arch_develop.md](./arch_develop.md#monorepo-structure
- `.vscode/launch.json` : defines VSCode launch configs useful for Toolkit
developers, e.g. the `Extension Tests` config runs all tests in `src/test/`.

Many tests required running in an activated extension environment, but the core-lib is just a library and does not have any extension to activate itself. Core-lib tests are run from `packages/toolkit`, and web tests are run from `packages/amazonq`.

## How we test

VSCode documentation describes an [extension testing](https://code.visualstudio.com/api/working-with-extensions/testing-extension)
Expand Down
20 changes: 2 additions & 18 deletions docs/arch_develop.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ If you are considering contributing, please consider whether your implementation
library or in `packages/toolkit`. If your work could be re-used by other packages (e.g. auth mechanisms,
utilities), then it may belong in the core library. If instead you are adding something toolkit specific
(eg. an integration to a new AWS service in the Explorer Tree), consider putting it in `packages/toolkit`.
To import from the core library, please export your desired code using `index.ts` files, and add an appropriate `exports` statement
To import from the core library, please export your desired code using `index.ts` files and add an appropriate `exports` statement
in `packages/core/package.json`.

Unless otherwise stated, the documentation throughout this project is referring to the code and
Expand Down Expand Up @@ -51,25 +51,9 @@ Current quirks of the current monorepo status that should be resolved/evaluated
- Pre-release only publishes packages/toolkit extension directly. It should be extended to other added extensions. See [`release.yml`](../.github/workflows/release.yml)
- VSCode does not support inheriting/extending `.vscode/` settings: https://github.com/microsoft/vscode/issues/15909

Additional quirks introduced by creating a core library from the original extension code:

- Tests are ran from `packages/core/`
- Extension runs from `packages/toolkit`
- Extension tests run from the core lib. Since some of the tests require an extension context/sandbox, we initiate a "fake" extension to run these tests. This is also why there are vscode extension properties in the package.json
- Some of original extension code (that now lives in `packages/core`) depends on the package.json, specifically the contributes section. This section is very large AND needs to be present in both the core library and toolkit extension package.jsons. The core library code needs access to this section to create types, set up SAM debuggers, etc. The toolkit needs this section during packaging/debugging so that the extension can run in vscode. The short term solution was to creat a [build script](../packages/toolkit/scripts/build/handlePackageJson.ts) to copy necessary fields over to the toolkit extension during packaging and debugging.

### Contributes and Settings

Some components of the core library depend on the `package.json`s of the extensions. One example of this is compile time checking of the extension's settings values. However, VSCode also requires a complete local `package.json` for the individual extensions during packaging. As a temporary workaround to this, we are using scripts to auto-populate the `package.json`s for the individual extensions from the core `package.json`.

- [`packages/toolkit/../handlePackageJson.ts`](../packages/toolkit/scripts/build/handlePackageJson.ts)
- Copies the entirety of the `contributes` and `engine` sections, except for `configuration.properties` relating to `packages/amazon`.
- Restores to the original barebones `package.json` after packaging/debugging, to avoid a large amount of duplicate code.
- To develop for the Toolkit extension: add all changes to `packages/core/package.json`
- [`packages/amazonq/../syncPackageJson.ts`](../packages/amazonq/scripts/build/syncPackageJson.ts)
- Moves all Amazon Q related `configuration.properties` to the local `package.json` only, overwriting anything that exists with the same name locally.
- Does not restore, it is a superset of what exists in `packages/core` for `configuration.properties`.
- To develop for the Amazon Q extension: add all changes to `packages/amazonq/package.json`, EXCEPT for settings that are references by code in the core library, or settings that already exist in the core `package.json`
`packages/toolkit/` and `packages/amazonq` have independent extension packageJSON files. They do not rely on `packages/core/package.json`. However, to get typed icons in the core-lib we require a place to store the icon entries. This currently happens in `packages/core/package.json`. See [`icons.md`](./icons.md) for more information.

If you are modifying or registering new debuggers in VS Code via the `debuggers` contribution point, you may need to regenerate the [definitions file](../packages/core/src/shared/sam/debugger/awsSamDebugConfiguration.gen.ts). After updating ['toolkit/package.json'](../packages/toolkit/package.json), run `npm run generateConfigurationAttributes -w packages/toolkit`

Expand Down
7 changes: 5 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 19 additions & 0 deletions packages/amazonq/.vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,25 @@
"order": 2
}
},
{
"name": "Extension Tests (web)",
"type": "extensionHost",
"debugWebWorkerHost": true,
"request": "launch",
"args": [
"--disable-extension=amazonwebservices.aws-toolkit-vscode",
"--extensionDevelopmentPath=${workspaceFolder}",
"--extensionDevelopmentKind=web",
"--extensionTestsPath=${workspaceFolder}/dist/test/web/testRunnerWebCore",
"${workspaceFolder}/../core/dist/src/testFixtures/workspaceFolder"
],
"outFiles": ["${workspaceFolder}/dist/**/*.js", "${workspaceFolder}/../core/dist/**/*.js"],
"preLaunchTask": "webRun",
"presentation": {
"group": "3_ExtensionTests",
"order": 3
}
},
{
"name": "E2E Test (current file)",
"type": "extensionHost",
Expand Down
3 changes: 1 addition & 2 deletions packages/amazonq/.vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@
// Since `webpack --watch` never terminates (but finishes packaging at some point),
// VS Code uses this to parse the CLI output to pattern match something that indicates it is done
"problemMatcher": "$ts-webpack-watch",
"dependsOn": ["copyPackageJson"],
"options": {
"cwd": "${workspaceFolder}/../../packages/core"
}
Expand All @@ -124,7 +123,7 @@
"label": "webRunTerminate",
"command": "echo ${input:webRunTerminate}",
"type": "shell",
"dependsOn": ["restorePackageJson"]
"dependsOn": []
},
// ---------- End: Web Mode Tasks ----------
{
Expand Down
11 changes: 6 additions & 5 deletions packages/amazonq/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,20 @@
"browser": "./dist/src/extensionWeb",
"scripts": {
"vscode:prepublish": "npm run clean && npm run buildScripts && webpack --mode production",
"buildScripts": "npm run generateNonCodeFiles && npm run copyFiles && npm run generateIcons && npm run generateSettings && npm run syncPackageJson && tsc -p ./ --noEmit",
"buildScripts": "npm run generateNonCodeFiles && npm run copyFiles && npm run generateIcons && npm run generateSettings && tsc -p ./ --noEmit",
"generateNonCodeFiles": "ts-node ../../scripts/generateNonCodeFiles.ts",
"copyFiles": "ts-node ./scripts/build/copyFiles.ts",
"syncPackageJson": "ts-node ./scripts/build/syncPackageJson.ts",
"clean": "ts-node ../../scripts/clean.ts dist/ LICENSE NOTICE",
"compile": "npm run clean && npm run buildScripts && webpack --mode development",
"compile": "npm run clean && npm run buildScripts && webpack",
"compileDev": "npm run testCompile && webpack --mode development",
"compileOnly": "tsc -p ./",
"package": "ts-node ../../scripts/package.ts",
"lint": "true",
"watch": "npm run clean && npm run buildScripts && tsc -watch -p ./",
"testCompile": "npm run clean && npm run buildScripts && npm run compileOnly",
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/test.ts dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/testE2E.ts dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
"test": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts unit dist/test/unit/index.js ../core/dist/src/testFixtures/workspaceFolder",
"testE2E": "npm run testCompile && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts e2e dist/test/e2e/index.js ../core/dist/src/testFixtures/workspaceFolder",
"testWeb": "npm run compileDev && c8 --allowExternal ts-node ../core/scripts/test/launchTest.ts web dist/test/web/testRunnerWebCore.js",
"webRun": "npx @vscode/test-web --open-devtools --browserOption=--disable-web-security --waitForDebugger=9222 --extensionDevelopmentPath=. .",
"webWatch": "npm run clean && npm run buildScripts && webpack --mode development --watch",
"serve": "webpack serve --config-name mainServe --mode development",
Expand Down
37 changes: 0 additions & 37 deletions packages/amazonq/scripts/build/syncPackageJson.ts

This file was deleted.

8 changes: 3 additions & 5 deletions packages/amazonq/test/e2e/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { runTests } from 'aws-core-vscode/test'
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'

export function run(): Promise<void> {
return runTests(
process.env.TEST_DIR ?? 'test/e2e',
['../../core/dist/src/testInteg/globalSetup.test.ts'],
VSCODE_EXTENSION_ID.amazonq
)
return runTests(process.env.TEST_DIR ?? 'test/e2e', VSCODE_EXTENSION_ID.amazonq, [
'../../core/dist/src/testInteg/globalSetup.test.ts',
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import assert from 'assert'
import vscode from 'vscode'
import sinon from 'sinon'
import { join } from 'path'
import { getTestWorkspaceFolder } from 'aws-core-vscode/testInteg'
import { getTestWorkspaceFolder } from 'aws-core-vscode/test'
import { CodeAnalysisScope, ZipUtil } from 'aws-core-vscode/codewhisperer'
import { codeScanTruncDirPrefix } from 'aws-core-vscode/codewhisperer'
import { ToolkitError } from 'aws-core-vscode/shared'
Expand Down
8 changes: 3 additions & 5 deletions packages/amazonq/test/unit/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ import { runTests } from 'aws-core-vscode/test'
import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'

export function run(): Promise<void> {
return runTests(
process.env.TEST_DIR ?? 'test/unit',
['../../core/dist/src/test/globalSetup.test.ts'],
VSCODE_EXTENSION_ID.amazonq
)
return runTests(process.env.TEST_DIR ?? ['test/unit'], VSCODE_EXTENSION_ID.amazonq, [
'../../core/dist/src/test/globalSetup.test.ts',
])
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
*/

import assert from 'assert'
import globals from '../shared/extensionGlobals'
import { globals, ToolkitGlobals } from 'aws-core-vscode/shared'

describe('activation', async () => {
it('defines a region provider that can provide regions when in web mode', async () => {
assert(globals.regionProvider.getRegions().length > 0)
assert((globals as unknown as ToolkitGlobals).regionProvider.getRegions().length > 0)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import assert from 'assert'
import { randomUUID } from '../../shared/crypto'
import { randomUUID } from 'aws-core-vscode/shared'

describe('crypto', function () {
describe('randomUUID()', function () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
*/

import assert from 'assert'
import globals from '../../shared/extensionGlobals'
import fs from '../../shared/fs/fs'
import { fs, globals } from 'aws-core-vscode/shared'

describe('FileSystem', function () {
it('getUserHomeDir()', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
*
* Any web specific tests should be made within their own `describe()`.
*/
import { timeoutUtilsDescribe } from '../../../test/shared/utilities/timeoutUtils.test'
import { timeoutUtilsDescribe } from 'aws-core-vscode/testWeb'
timeoutUtilsDescribe
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
* The following was influenced by this guide: https://code.visualstudio.com/api/extension-guides/web-extensions
*/

import { VSCODE_EXTENSION_ID } from 'aws-core-vscode/utils'
import 'mocha' // Imports mocha for the browser, defining the `mocha` global.
import * as vscode from 'vscode'
import { VSCODE_EXTENSION_ID } from '../shared/extensions'

export async function run(): Promise<void> {
await activateToolkitExtension()
await activateExtension()
return new Promise(async (resolve, reject) => {
setupMocha()
gatherTestFiles()
Expand Down Expand Up @@ -45,8 +45,13 @@ function gatherTestFiles() {
*
* So this function ensures the extension has fully activated.
*/
async function activateToolkitExtension() {
await vscode.extensions.getExtension(VSCODE_EXTENSION_ID.awstoolkitcore)?.activate()
async function activateExtension() {
const extId = VSCODE_EXTENSION_ID.amazonq
const ext = vscode.extensions.getExtension(extId)
if (!ext) {
throw new Error(`Extension '${extId}' not found, can't activate it to run tests.`)
}
await vscode.extensions.getExtension(VSCODE_EXTENSION_ID.amazonq)?.activate()
}

function runMochaTests(resolve: (value: void | PromiseLike<void>) => void, reject: (reason?: any) => void) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import * as assert from 'assert'
import { isWeb } from '../shared/extensionGlobals'
import { isWeb } from 'aws-core-vscode/shared'

describe('isWeb', function () {
it('returns true when in web mode', function () {
Expand Down
1 change: 1 addition & 0 deletions packages/amazonq/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ module.exports = (env, argv) => {
...baseWebConfigsFactory(env, argv),
entry: {
'src/extensionWeb': './src/extensionWeb.ts',
'test/web/testRunnerWebCore': './test/web/testRunner.ts',
},
}

Expand Down
Loading
Loading