Skip to content

Commit 93ab2c4

Browse files
authored
Fix: Include tests in webpack compilation as individual *.test.js files with TypeScript checking, test fixtures, and watch mode support (#7856)
* Initial plan * Initial analysis of test compilation issue Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix: Include tests in webpack compilation for node target * Fix: Include test files in TypeScript checking for webpack builds Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Merge branch 'main' into copilot/fix-e7c8c5a5-dc38-4029-b1a7-504cde95862f * Just use the tsconfig.json file * Generate individual *.test.js files from webpack compilation Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Update test files * Fix: Remove mocha import to use global functions in test files Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix: Copy test fixtures to dist directory during webpack builds Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Fix: Update watch task to copy test fixtures before starting webpack watch Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Replace preprocess-fixtures script with webpack plugin for automatic fixture copying Co-authored-by: alexr00 <38270282+alexr00@users.noreply.github.com> * Get fixtures copied correctly * Last step! Remove the webpack scheme from the source maps * Exclude tests from package * Clean up
1 parent 492546c commit 93ab2c4

16 files changed

Lines changed: 140 additions & 43 deletions

.vscode-test.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ function generateConfig(label) {
88
/** @type {import('@vscode/test-cli').TestConfiguration} */
99
let config = {
1010
label,
11-
files: ["out/**/*.test.js"],
11+
files: ["dist/**/*.test.js"],
1212
version: "insiders",
1313
srcDir: "src",
1414
launchArgs: [

.vscodeignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ node_modules/**
1212
scripts/**
1313
src/**
1414
webviews/**
15+
**/test/**
1516
.eslintcache*
1617
.eslintignore
1718
.eslintrc*

src/test/browser/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
6+
// @ts-nocheck
17
// This file is providing the test runner to use when running extension tests.
28
import * as vscode from 'vscode';
39
require('mocha/mocha');

src/test/builders/graphql/latestReviewCommitBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { LatestReviewCommitResponse } from '../../../github/graphql';
88

99
import { RateLimitBuilder } from './rateLimitBuilder';
1010

11-
type Repository = LatestReviewCommitResponse['repository'];
11+
type Repository = NonNullable<LatestReviewCommitResponse['repository']>;
1212
type PullRequest = Repository['pullRequest'];
1313
type ViewerLatestReview = PullRequest['viewerLatestReview'];
1414
type Commit = ViewerLatestReview['commit'];

src/test/builders/graphql/pullRequestBuilder.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ const RefBuilder = createBuilderClass<Ref>()({
3737
}),
3838
});
3939

40-
type Repository = PullRequestResponse['repository'];
40+
type Repository = NonNullable<PullRequestResponse['repository']>;
4141
type PullRequest = Repository['pullRequest'];
4242
type Author = PullRequest['author'];
4343
type AssigneesConn = PullRequest['assignees'];

src/test/builders/graphql/timelineEventsBuilder.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,14 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
16
import { createBuilderClass, createLink } from '../base';
27
import { TimelineEventsResponse } from '../../../github/graphql';
38

49
import { RateLimitBuilder } from './rateLimitBuilder';
510

6-
type Repository = TimelineEventsResponse['repository'];
11+
type Repository = NonNullable<TimelineEventsResponse['repository']>;
712
type PullRequest = Repository['pullRequest'];
813
type TimelineConn = PullRequest['timelineItems'];
914

src/test/builders/rest/pullRequestBuilder.ts

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
16
import { UserBuilder } from './userBuilder';
2-
import { RefBuilder } from './refBuilder';
7+
import { NonNullUserRefBuilder, RefBuilder } from './refBuilder';
38
import { createLink, createBuilderClass } from '../base';
49
import { OctokitCommon } from '../../../github/common';
510

@@ -40,8 +45,8 @@ export const PullRequestBuilder = createBuilderClass<PullRequestUnion>()({
4045
closed_at: { default: '' },
4146
merged_at: { default: '' },
4247
merge_commit_sha: { default: '' },
43-
head: { linked: RefBuilder },
44-
base: { linked: RefBuilder },
48+
head: { linked: NonNullUserRefBuilder },
49+
base: { linked: NonNullUserRefBuilder },
4550
draft: { default: false },
4651
merged: { default: false },
4752
mergeable: { default: true },
Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License. See License.txt in the project root for license information.
4+
*--------------------------------------------------------------------------------------------*/
5+
16
import { UserBuilder } from './userBuilder';
27
import { RepositoryBuilder } from './repoBuilder';
38
import { createBuilderClass } from '../base';
49
import { OctokitCommon } from '../../../github/common';
510

611
type RefUnion = OctokitCommon.PullsListResponseItemHead & OctokitCommon.PullsListResponseItemBase;
712

8-
export const RefBuilder = createBuilderClass<RefUnion>()({
13+
export const RefBuilder = createBuilderClass<NonNullable<RefUnion>>()({
914
label: { default: 'octocat:new-feature' },
1015
ref: { default: 'new-feature' },
1116
user: { linked: UserBuilder },
@@ -14,4 +19,15 @@ export const RefBuilder = createBuilderClass<RefUnion>()({
1419
repo: { linked: <any>RepositoryBuilder },
1520
});
1621

22+
// Variant where user is guaranteed non-null.
23+
type NonNullUserRef = Omit<RefUnion, 'user'> & { user: NonNullable<RefUnion['user']> };
24+
25+
export const NonNullUserRefBuilder = createBuilderClass<NonNullUserRef>()({
26+
label: { default: 'octocat:new-feature' },
27+
ref: { default: 'new-feature' },
28+
user: { linked: UserBuilder }, // non-null guarantee
29+
sha: { default: '0000000000000000000000000000000000000000' },
30+
repo: { linked: <any>RepositoryBuilder },
31+
});
32+
1733
export type RefBuilder = InstanceType<typeof RefBuilder>;

src/test/builders/rest/repoBuilder.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ type License = RepoUnion['license'];
1616
type Permissions = RepoUnion['permissions'];
1717
type CodeOfConduct = RepoUnion['code_of_conduct'];
1818

19-
export const RepositoryBuilder = createBuilderClass<RepoUnion>()({
19+
export const RepositoryBuilder = createBuilderClass<NonNullable<RepoUnion>>()({
2020
id: { default: 0 },
2121
node_id: { default: 'node0' },
2222
name: { default: 'reponame' },
@@ -123,9 +123,9 @@ export const RepositoryBuilder = createBuilderClass<RepoUnion>()({
123123
name: { default: 'name' },
124124
url: { default: 'https://github.com/octocat/reponame' },
125125
}),
126-
forks: { default: null },
127-
open_issues: { default: null },
128-
watchers: { default: null },
126+
forks: { default: 0 },
127+
open_issues: { default: 0 },
128+
watchers: { default: 0 },
129129
});
130130

131131
export type RepositoryBuilder = InstanceType<typeof RepositoryBuilder>;

src/test/builders/rest/userBuilder.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ type UserUnion =
1717
| OctokitCommon.PullsListResponseItemHeadRepoOwner
1818
| OctokitCommon.IssuesListEventsForTimelineResponseItemActor;
1919

20-
export const UserBuilder = createBuilderClass<Required<UserUnion>>()({
20+
type NonNullUser = NonNullable<UserUnion>;
21+
22+
export const UserBuilder = createBuilderClass<NonNullUser>()({
2123
id: { default: 0 },
2224
node_id: { default: 'node0' },
2325
login: { default: 'octocat' },

0 commit comments

Comments
 (0)