Skip to content

test: fix ts compiler errors #23130

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 6, 2022
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
12 changes: 12 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,12 @@ jobs:
- custom_attach_workspace
- run: yarn build

build-bazel-e2e:
executor: action-executor
steps:
- custom_attach_workspace
- run: yarn bazel build //tests/legacy-cli/...

test:
executor: test-executor
resource_class: xlarge
Expand Down Expand Up @@ -379,6 +385,12 @@ workflows:
requires:
- build

# Compile the e2e tests with bazel to ensure the non-runtime typescript
# compilation completes succesfully.
- build-bazel-e2e:
requires:
- build

# Windows jobs
- e2e-cli-win:
requires:
Expand Down
12 changes: 12 additions & 0 deletions lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "lib",
srcs = ["packages.ts"],
visibility = ["//visibility:public"],
deps = [
"//packages/angular_devkit/core",
"@npm//@types/node",
"@npm//typescript",
],
)
25 changes: 25 additions & 0 deletions tests/legacy-cli/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "runner",
testonly = True,
srcs = glob(["**/*.ts"]),
data = [
"verdaccio.yaml",
"verdaccio_auth.yaml",
],
deps = [
"//packages/angular_devkit/core",
"//packages/angular_devkit/core/node",
"//tests/legacy-cli/e2e/assets",
"//tests/legacy-cli/e2e/utils",
"@npm//@types/glob",
"@npm//@types/yargs-parser",
"@npm//ansi-colors",
"@npm//yargs-parser",

# Loaded dynamically at runtime, not compiletime deps
"//tests/legacy-cli/e2e/setup",
"//tests/legacy-cli/e2e/tests",
],
)
11 changes: 11 additions & 0 deletions tests/legacy-cli/e2e/assets/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("//tools:defaults.bzl", "js_library")

js_library(
name = "assets",
srcs = glob(["**"]),
visibility = ["//visibility:public"],
deps = [
"@npm//jasmine-spec-reporter",
"@npm//ts-node",
],
)
8 changes: 8 additions & 0 deletions tests/legacy-cli/e2e/ng-snapshot/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "ng-snapshot",
srcs = [],
data = ["package.json"],
visibility = ["//visibility:public"],
)
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/setup/010-local-publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { execWithEnv, extractNpmEnv } from '../utils/process';
import { isPrereleaseCli } from '../utils/project';

export default async function () {
const testRegistry = getGlobalVariable('package-registry');
const testRegistry: string = getGlobalVariable('package-registry');
await execWithEnv(
'npm',
[
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/setup/100-global-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export default async function () {
return;
}

const testRegistry = getGlobalVariable('package-registry');
const testRegistry: string = getGlobalVariable('package-registry');

// Install global Angular CLI.
await silentNpm('install', '--global', '@angular/cli', `--registry=${testRegistry}`);
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/setup/300-log-environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export default async function () {
return;
}

console.log(` ${envName}: ${process.env[envName].replace(/[\n\r]+/g, '\n ')}`);
console.log(` ${envName}: ${process.env[envName]!.replace(/[\n\r]+/g, '\n ')}`);
});

await node('--version');
Expand Down
4 changes: 1 addition & 3 deletions tests/legacy-cli/e2e/setup/500-create-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@ export default async function () {
process.chdir(argv.reuse);
await gitClean();
} else {
const extraArgs = [];

// Ensure local test registry is used when outside a project
await setNPMConfigRegistry(true);

await ng('new', 'test-project', '--skip-install', ...extraArgs);
await ng('new', 'test-project', '--skip-install');
await expectFileToExist(join(process.cwd(), 'test-project'));
process.chdir('./test-project');

Expand Down
11 changes: 11 additions & 0 deletions tests/legacy-cli/e2e/setup/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "setup",
testonly = True,
srcs = glob(["**/*.ts"]),
visibility = ["//visibility:public"],
deps = [
"//tests/legacy-cli/e2e/utils",
],
)
20 changes: 20 additions & 0 deletions tests/legacy-cli/e2e/tests/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "tests",
testonly = True,
srcs = glob(["**/*.ts"]),
visibility = ["//visibility:public"],
deps = [
"//tests/legacy-cli/e2e/ng-snapshot",
"//tests/legacy-cli/e2e/utils",
"@npm//@types/express",
"@npm//@types/glob",
"@npm//@types/node-fetch",
"@npm//@types/semver",
"@npm//express",
"@npm//glob",
"@npm//node-fetch",
"@npm//semver",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ export default async function () {

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
if (isSnapshotBuild) {
const packagesToInstall = [];
const packagesToInstall: string[] = [];
await updateJsonFile('package.json', (packageJson) => {
const dependencies = packageJson['dependencies'];
// Iterate over all of the packages to update them to the snapshot version.
for (const [name, version] of Object.entries(snapshots.dependencies)) {
for (const [name, version] of Object.entries(
snapshots.dependencies as { [p: string]: string },
)) {
if (name in dependencies && dependencies[name] !== version) {
packagesToInstall.push(version);
}
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/build/platform-server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ export default async function () {

const isSnapshotBuild = getGlobalVariable('argv')['ng-snapshots'];
if (isSnapshotBuild) {
const packagesToInstall = [];
const packagesToInstall: string[] = [];
await updateJsonFile('package.json', (packageJson) => {
const dependencies = packageJson['dependencies'];
// Iterate over all of the packages to update them to the snapshot version.
for (const [name, version] of Object.entries(snapshots.dependencies)) {
for (const [name, version] of Object.entries<string>(snapshots.dependencies)) {
if (name in dependencies && dependencies[name] !== version) {
packagesToInstall.push(version);
}
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/build/prod-build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async function () {
}

const indexContent = await readFile('dist/test-project/index.html');
const mainPath = indexContent.match(/src="(main\.[0-9a-zA-Z]{0,32}\.js)"/)[1];
const mainPath = indexContent.match(/src="(main\.[0-9a-zA-Z]{0,32}\.js)"/)![1];

// Content checks
await expectFileToMatch(`dist/test-project/${mainPath}`, bootstrapRegExp);
Expand Down
3 changes: 2 additions & 1 deletion tests/legacy-cli/e2e/tests/commands/add/add-pwa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ export default async function () {

// It should correctly generate assetGroups and include at least one URL in each group.
const ngswJson = JSON.parse(await readFile(ngswPath));
const assetGroups = ngswJson.assetGroups.map(({ name, urls }) => ({
// @ts-ignore
const assetGroups: any[] = ngswJson.assetGroups.map(({ name, urls }) => ({
name,
urlCount: urls.length,
}));
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-basehref.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';
import { externalServer, langTranslations, setupI18nConfig } from './setup';

const baseHrefs = {
const baseHrefs: { [l: string]: string } = {
'en-US': '/en/',
fr: '/fr-FR/',
de: '',
Expand Down Expand Up @@ -59,7 +59,7 @@ export default async function () {
await ng('e2e', `--configuration=${lang}`, '--port=0');

// Execute Application E2E tests for a production build without dev server
const server = externalServer(outputPath, baseHrefs[lang] || '/');
const server = externalServer(outputPath, (baseHrefs[lang] as string) || '/');
try {
await ng(
'e2e',
Expand Down
6 changes: 3 additions & 3 deletions tests/legacy-cli/e2e/tests/i18n/ivy-localize-hashes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async function () {
continue;
}

hashes.set(`${lang}/${match.groups.name}`, match.groups.hash);
hashes.set(`${lang}/${match!.groups!.name}`, match!.groups!.hash);
}
}

Expand All @@ -48,12 +48,12 @@ export default async function () {
continue;
}

const id = `${lang}/${match.groups.name}`;
const id = `${lang}/${match!.groups!.name}`;
const hash = hashes.get(id);
if (!hash) {
throw new Error('Unexpected output entry: ' + id);
}
if (hash === match.groups.hash) {
if (hash === match!.groups!.hash) {
throw new Error('Hash value did not change for entry: ' + id);
}

Expand Down
6 changes: 3 additions & 3 deletions tests/legacy-cli/e2e/tests/i18n/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ export const formats = {
'json': {
ext: 'json',
sourceCheck: '"locale": "en-US"',
replacements: [],
replacements: [] as RegExp[][],
},
'arb': {
ext: 'arb',
sourceCheck: '"@@locale": "en-US"',
replacements: [],
replacements: [] as RegExp[][],
},
};

Expand Down Expand Up @@ -248,7 +248,7 @@ export async function setupI18nConfig(format: keyof typeof formats = 'xlf') {
for (const { lang, translationReplacements } of langTranslations) {
if (lang != sourceLocale) {
await copyFile(translationFile, `src/locale/messages.${lang}.${formats[format].ext}`);
for (const replacements of translationReplacements) {
for (const replacements of translationReplacements!) {
await replaceInFile(
`src/locale/messages.${lang}.${formats[format].ext}`,
new RegExp(replacements[0], 'g'),
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/misc/completion-prompt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ source <(ng completion script)

const localCliDir = path.join(projectDir, 'node_modules', '.bin');
const localCliBinary = path.join(localCliDir, 'ng');
const pathDirs = process.env['PATH'].split(':');
const pathDirs = process.env['PATH']!.split(':');
const pathEnvVar = [...pathDirs, localCliDir].join(':');
const { stdout } = await execWithEnv(localCliBinary, ['version'], {
...DEFAULT_ENV,
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/misc/e2e-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { killAllProcesses, ng } from '../../utils/process';
import { updateJsonFile } from '../../utils/project';

export default async function () {
const interfaces = [].concat.apply([], Object.values(os.networkInterfaces()));
const interfaces = Object.values(os.networkInterfaces()).flat() as os.NetworkInterfaceInfo[];
let host = '';
for (const { family, address, internal } of interfaces) {
if (family === 'IPv4' && !internal) {
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/misc/http-headers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export default async function () {
};
});

let errorMessage = null;
let errorMessage: string | null = null;
try {
await ng('e2e');
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/tests/misc/npm-7.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export default async function () {

const currentDirectory = process.cwd();

const extraArgs = [];
const extraArgs: string[] = [];
if (isPrereleaseCli()) {
extraArgs.push('--next');
}
Expand Down
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/tests/misc/public-host.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ export default function () {

const firstLocalIp = Object.values(os.networkInterfaces())
.flat()
.filter((ni) => ni.family === 'IPv4' && !ni.internal)
.map((ni) => ni.address)
.filter((ni) => ni?.family === 'IPv4' && !ni?.internal)
.map((ni) => ni!.address)
.shift();
const publicHost = `${firstLocalIp}:4200`;
const localAddress = `http://${publicHost}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default async function () {
delete process.env['NPM_CONFIG_REGISTRY'];
const worksMessage = 'We analyzed your package.json';

const extraArgs = [];
const extraArgs: string[] = [];
if (isPrereleaseCli()) {
extraArgs.push('--next');
}
Expand Down
25 changes: 25 additions & 0 deletions tests/legacy-cli/e2e/utils/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
load("//tools:defaults.bzl", "ts_library")

ts_library(
name = "utils",
testonly = True,
srcs = glob(["**/*.ts"]),
visibility = ["//visibility:public"],
deps = [
"//lib",
"//tests/legacy-cli/e2e/ng-snapshot",
"@npm//@types/glob",
"@npm//@types/node-fetch",
"@npm//@types/semver",
"@npm//@types/yargs-parser",
"@npm//ansi-colors",
"@npm//glob",
"@npm//protractor",
"@npm//puppeteer",
"@npm//rxjs",
"@npm//semver",
"@npm//tree-kill",
"@npm//verdaccio",
"@npm//verdaccio-auth-memory",
],
)
4 changes: 2 additions & 2 deletions tests/legacy-cli/e2e/utils/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ export function setGlobalVariable(name: string, value: any) {
global[name] = value;
}

export function getGlobalVariable(name: string): any {
export function getGlobalVariable<T = any>(name: string): T {
if (!(name in global)) {
throw new Error(`Trying to access variable "${name}" but it's not defined.`);
}
return global[name];
return global[name] as T;
}
2 changes: 1 addition & 1 deletion tests/legacy-cli/e2e/utils/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function symlinkFile(from: string, to: string, type?: string): Promise<vo
return fs.symlink(from, to, type);
}

export function createDir(path: string): Promise<string> {
export function createDir(path: string): Promise<string | undefined> {
return fs.mkdir(path, { recursive: true });
}

Expand Down
Loading