Skip to content

Commit fbbe8a5

Browse files
authored
Fix test explorer tests in nightly build (#1689)
* Fix test explorer tests in nightly build Nightly tests think is production build because we install the extension so also check that not a test run Also turning on running the tests in against the VSIX for CI builds so we catch issues like this before merging Issue: #1686 * Make sure token is available
1 parent 063ebea commit fbbe8a5

File tree

4 files changed

+25
-1
lines changed

4 files changed

+25
-1
lines changed

.github/workflows/pull_request.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ jobs:
4545
4646
tests:
4747
name: ${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && 'Full Test Run' || 'Test'}}
48+
needs: package
4849
uses: swiftlang/github-workflows/.github/workflows/swift_package_test.yml@main
4950
with:
51+
needs_token: true
5052
# Linux
5153
linux_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly-6.2"},{"swift_version": "nightly-main"}]'
5254
linux_env_vars: |
@@ -55,13 +57,18 @@ jobs:
5557
NVM_DIR=/usr/local/nvm
5658
CI=1
5759
FAST_TEST_RUN=${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '0' || '1'}}
60+
VSCODE_SWIFT_VSIX_ID=${{needs.package.outputs.artifact-id}}
61+
GITHUB_REPOSITORY=${{github.repository}}
5862
linux_pre_build_command: . .github/workflows/scripts/setup-linux.sh
5963
linux_build_command: ./scripts/test.sh
6064
# Windows
6165
windows_exclude_swift_versions: '[{"swift_version": "nightly-6.1"},{"swift_version": "nightly-6.2"},{"swift_version": "nightly"}]'
6266
windows_env_vars: |
6367
CI=1
6468
FAST_TEST_RUN=${{ contains(github.event.pull_request.labels.*.name, 'full-test-run') && '0' || '1'}}
69+
VSCODE_SWIFT_VSIX_ID=${{needs.package.outputs.artifact-id}}
70+
VSCODE_SWIFT_VSIX=vscode-swift.vsix
71+
GITHUB_REPOSITORY=${{github.repository}}
6572
windows_pre_build_command: .github\workflows\scripts\windows\setup.ps1
6673
windows_build_command: scripts\test_windows.ps1
6774
enable_windows_docker: false

.vscode-test.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ module.exports = defineConfig({
7070
extensionDevelopmentPath: vsixPath
7171
? [`${__dirname}/.vscode-test/extensions/${publisher}.${name}-${version}`]
7272
: undefined,
73+
env: {
74+
VSCODE_TEST: "1",
75+
},
7376
mocha: {
7477
ui: "tdd",
7578
color: true,
@@ -106,6 +109,9 @@ module.exports = defineConfig({
106109
extensionDevelopmentPath: vsixPath
107110
? [`${__dirname}/.vscode-test/extensions/${publisher}.${name}-${version}`]
108111
: undefined,
112+
env: {
113+
VSCODE_TEST: "1",
114+
},
109115
mocha: {
110116
ui: "tdd",
111117
color: true,
@@ -130,6 +136,9 @@ module.exports = defineConfig({
130136
files: ["dist/test/common.js", "dist/test/unit-tests/**/*.test.js"],
131137
version: process.env["VSCODE_VERSION"] ?? "stable",
132138
launchArgs: launchArgs.concat("--disable-extensions"),
139+
env: {
140+
VSCODE_TEST: "1",
141+
},
133142
mocha: {
134143
ui: "tdd",
135144
color: true,

src/TestExplorer/TestRunner.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
execFile,
2424
getErrorDescription,
2525
IS_PRODUCTION_BUILD,
26+
IS_RUNNING_UNDER_TEST,
2627
} from "../utilities/utilities";
2728
import { createSwiftTask } from "../tasks/SwiftTaskProvider";
2829
import configuration from "../configuration";
@@ -244,7 +245,7 @@ export class TestRunProxy {
244245
}
245246

246247
private clearEnqueuedTest(test: vscode.TestItem) {
247-
if (IS_PRODUCTION_BUILD) {
248+
if (IS_PRODUCTION_BUILD && !IS_RUNNING_UNDER_TEST) {
248249
// `runState.enqueued` exists only for test validation purposes.
249250
return;
250251
}

src/utilities/utilities.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@ export const IS_PRODUCTION_BUILD = process.env.NODE_ENV === "production";
3636
*/
3737
export const IS_RUNNING_IN_CI = process.env.CI === "1";
3838

39+
/**
40+
* Whether or not the code is being run as part of a test suite.
41+
*
42+
* This will NOT be removed when the extension is packaged into a VSIX.
43+
*/
44+
export const IS_RUNNING_UNDER_TEST = process.env.VSCODE_TEST === "1";
45+
3946
/**
4047
* Get required environment variable for Swift product
4148
*

0 commit comments

Comments
 (0)