Skip to content

Commit 25c68f8

Browse files
committed
test: add validation test for extension pre-standalone default
This allows us to verify that the extension properly deals with pre-v19 projects and `standalone: false`
1 parent 43e792d commit 25c68f8

16 files changed

+166
-8
lines changed

.bazelignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ integration/project/node_modules/
55
integration/project/libs/post/node_modules
66
integration/project/dist/
77
integration/workspace/node_modules/
8+
integration/pre_standalone_project/node_modules/
89

910
override_rename_ts_plugin/node_modules
1011
server/node_modules

.circleci/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ jobs:
2323
- node/install-packages:
2424
app-dir: integration/pre_apf_project
2525
pkg-manager: yarn
26+
- node/install-packages:
27+
app-dir: integration/pre_standalone_project
28+
pkg-manager: yarn
2629
- node/install-packages:
2730
app-dir: integration/workspace
2831
pkg-manager: yarn

WORKSPACE

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,3 +153,18 @@ npm_translate_lock(
153153
load("@npm_integration_project//:repositories.bzl", npm_integration_project_repositories = "npm_repositories")
154154

155155
npm_integration_project_repositories()
156+
157+
npm_translate_lock(
158+
name = "npm_integration_pre_standalone_project",
159+
data = [
160+
"//integration/pre_standalone_project:package.json",
161+
"//integration/pre_standalone_project:pnpm-workspace.yaml",
162+
],
163+
npmrc = "//:.npmrc",
164+
pnpm_lock = "//integration/pre_standalone_project:pnpm-lock.yaml",
165+
verify_node_modules_ignored = "//:.bazelignore",
166+
)
167+
168+
load("@npm_integration_pre_standalone_project//:repositories.bzl", npm_integration_pre_standalone_project_repositories = "npm_repositories")
169+
170+
npm_integration_pre_standalone_project_repositories()

integration/lsp/BUILD.bazel

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ jasmine_test(
66
data = [
77
"//integration",
88
"//integration/project",
9+
"//integration/pre_standalone_project",
10+
"//integration/pre_standalone_project:node_modules/@angular/core",
11+
"//integration/pre_standalone_project:node_modules/@angular/common",
912
"//server:index",
1013
],
1114
args = ["*_spec.js"],

integration/lsp/ivy_spec.ts

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,17 @@
77
*/
88

99
import * as fs from 'fs';
10+
import {join} from 'path';
1011
import {promisify} from 'util';
1112
import {MessageConnection} from 'vscode-jsonrpc';
1213
import * as lsp from 'vscode-languageserver-protocol';
1314
import {URI} from 'vscode-uri';
1415

1516
import {ProjectLanguageService, ProjectLanguageServiceParams, SuggestStrictMode, SuggestStrictModeParams} from '../../common/notifications';
1617
import {GetComponentsWithTemplateFile, GetTcbRequest, GetTemplateLocationForComponent, IsInAngularProject} from '../../common/requests';
17-
import {APP_COMPONENT, APP_COMPONENT_MODULE_URI, APP_COMPONENT_URI, BAR_COMPONENT, BAR_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, IS_BAZEL, PROJECT_PATH, TSCONFIG} from '../test_constants';
18+
import {APP_COMPONENT, APP_COMPONENT_MODULE_URI, APP_COMPONENT_URI, BAR_COMPONENT, BAR_COMPONENT_URI, FOO_COMPONENT, FOO_COMPONENT_URI, FOO_TEMPLATE, FOO_TEMPLATE_URI, IS_BAZEL, PRE_STANDALONE_PROJECT_PATH, PROJECT_PATH, TSCONFIG} from '../test_constants';
1819

19-
import {convertPathToFileUrl, createConnection, createTracer, initializeServer, openTextDocument} from './test_utils';
20+
import {convertPathToFileUrl, createConnection, createTracer, initializeServer, openTextDocument, ServerOptions} from './test_utils';
2021

2122
const setTimeoutP = promisify(setTimeout);
2223

@@ -26,20 +27,25 @@ describe('Angular Ivy language server', () => {
2627
let client: MessageConnection;
2728

2829
beforeEach(async () => {
30+
await initServer({});
31+
});
32+
33+
afterEach(() => {
34+
client.dispose();
35+
});
36+
37+
async function initServer(options: Partial<ServerOptions>) {
2938
client = createConnection({
3039
ivy: true,
40+
...options,
3141
});
3242
// If debugging, set to
3343
// - lsp.Trace.Messages to inspect request/response/notification, or
3444
// - lsp.Trace.Verbose to inspect payload
3545
client.trace(lsp.Trace.Off, createTracer());
3646
client.listen();
3747
await initializeServer(client);
38-
});
39-
40-
afterEach(() => {
41-
client.dispose();
42-
});
48+
}
4349

4450
it('should handle hover on inline template', async () => {
4551
openTextDocument(client, APP_COMPONENT);
@@ -547,6 +553,15 @@ export class AppComponent {
547553
expect(response).toBeNull();
548554
});
549555

556+
it('should handle apps where standalone is not enabled by default (pre v19)', async () => {
557+
await initServer({angularCoreVersion: '18.0.0'})
558+
const moduleFile = join(PRE_STANDALONE_PROJECT_PATH, 'app/app.module.ts');
559+
560+
openTextDocument(client, moduleFile);
561+
const diagnostics = await getDiagnosticsForFile(client, moduleFile);
562+
expect(diagnostics.length).toBe(0);
563+
});
564+
550565
it('should provide a "go to component" codelens', async () => {
551566
openTextDocument(client, FOO_TEMPLATE);
552567
const codeLensResponse = await client.sendRequest(lsp.CodeLensRequest.type, {

integration/lsp/test_utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ export interface ServerOptions {
1818
ivy: boolean;
1919
includeAutomaticOptionalChainCompletions?: boolean;
2020
includeCompletionsWithSnippetText?: boolean;
21+
angularCoreVersion?: string;
2122
}
2223

2324
export function createConnection(serverOptions: ServerOptions): MessageConnection {
@@ -37,6 +38,9 @@ export function createConnection(serverOptions: ServerOptions): MessageConnectio
3738
if (serverOptions.includeCompletionsWithSnippetText) {
3839
argv.push('--includeCompletionsWithSnippetText');
3940
}
41+
if (serverOptions.angularCoreVersion) {
42+
argv.push('--angularCoreVersion', serverOptions.angularCoreVersion);
43+
}
4044
const server = fork(SERVER_PATH, argv, {
4145
cwd: PROJECT_PATH,
4246
// uncomment to debug server process
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
load("@npm_integration_pre_standalone_project//:defs.bzl", "npm_link_all_packages")
2+
load("@aspect_bazel_lib//lib:copy_to_bin.bzl", "copy_to_bin")
3+
4+
npm_link_all_packages(name = "node_modules")
5+
6+
copy_to_bin(
7+
name = "pre_standalone_project",
8+
srcs = glob(["**"]),
9+
visibility = [
10+
"//integration/lsp:__pkg__",
11+
],
12+
)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component, EventEmitter, Input, Output} from '@angular/core';
2+
3+
@Component({
4+
selector: 'my-app',
5+
template: `<h1>Hello {{name}}</h1>`,
6+
})
7+
export class AppComponent {
8+
name = 'Angular';
9+
@Input() appInput = '';
10+
@Output() appOutput = new EventEmitter<string>();
11+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import {CommonModule} from '@angular/common';
2+
import {NgModule} from '@angular/core';
3+
4+
import {AppComponent} from './app.component';
5+
import {FooComponent} from './foo.component';
6+
7+
@NgModule({
8+
imports: [
9+
CommonModule,
10+
],
11+
declarations: [
12+
AppComponent,
13+
FooComponent,
14+
],
15+
bootstrap: [AppComponent]
16+
})
17+
export class AppModule {
18+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{{title | uppercase}}
2+
<span class="subtitle">
3+
subtitle
4+
</span>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import {Component} from '@angular/core';
2+
3+
@Component({
4+
templateUrl: 'foo.component.html',
5+
})
6+
export class FooComponent {
7+
title = 'Foo Component';
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"name": "angular-ls-integration-test-project",
3+
"private": true,
4+
"dependencies": {
5+
"@angular/common": "18.2.10",
6+
"@angular/core": "18.2.10"
7+
}
8+
}

integration/pre_standalone_project/pnpm-lock.yaml

Lines changed: 36 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
packages:
2+
- .
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"compilerOptions": {
3+
"moduleResolution": "node",
4+
"experimentalDecorators": true,
5+
"target": "es2015",
6+
"strict": true,
7+
"typeRoots": [
8+
"node_modules/@types"
9+
]
10+
},
11+
"angularCompilerOptions": {
12+
"strictTemplates": true,
13+
"strictInjectionParameters": true
14+
}
15+
}

integration/test_constants.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ export const PACKAGE_ROOT = IS_BAZEL ? resolve(__dirname, '..') : resolve(__dirn
77
export const SERVER_PATH = IS_BAZEL ? join(PACKAGE_ROOT, 'server', 'index.js') :
88
join(PACKAGE_ROOT, 'dist', 'npm', 'server', 'index.js');
99
export const PROJECT_PATH = join(PACKAGE_ROOT, 'integration', 'project');
10+
export const PRE_STANDALONE_PROJECT_PATH =
11+
join(PACKAGE_ROOT, 'integration', 'pre_standalone_project');
12+
1013
export const APP_COMPONENT = join(PROJECT_PATH, 'app', 'app.component.ts');
1114
export const APP_COMPONENT_URI = convertPathToFileUrl(APP_COMPONENT);
1215
export const BAR_COMPONENT = join(PROJECT_PATH, 'app', 'bar.component.ts');
@@ -17,4 +20,4 @@ export const FOO_TEMPLATE = join(PROJECT_PATH, 'app', 'foo.component.html');
1720
export const FOO_TEMPLATE_URI = convertPathToFileUrl(FOO_TEMPLATE);
1821
export const FOO_COMPONENT = join(PROJECT_PATH, 'app', 'foo.component.ts');
1922
export const FOO_COMPONENT_URI = convertPathToFileUrl(FOO_COMPONENT);
20-
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');
23+
export const TSCONFIG = join(PROJECT_PATH, 'tsconfig.json');

0 commit comments

Comments
 (0)