Skip to content

fix: use srcRoot for angular build context #25090

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 4 commits into from
Dec 16, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@ macWorkflowFilters: &darwin-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'zachw/angular-ct-source-root', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
linuxArm64WorkflowFilters: &linux-arm64-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'zachw/angular-ct-source-root', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand All @@ -60,7 +62,7 @@ windowsWorkflowFilters: &windows-workflow-filters
when:
or:
- equal: [ develop, << pipeline.git.branch >> ]
- equal: [ 'mschile/fix_windows_flake', << pipeline.git.branch >> ]
- equal: [ 'zachw/angular-ct-source-root', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
value: << pipeline.git.branch >>
Expand Down Expand Up @@ -126,7 +128,7 @@ commands:
- run:
name: Check current branch to persist artifacts
command: |
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "ryanm/fix/issue-with-integrity-check" ]]; then
if [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "zachw/angular-ct-source-root" ]]; then
echo "Not uploading artifacts or posting install comment for this branch."
circleci-agent step halt
fi
Expand Down
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function createFakeContext (projectRoot: string, defaultProjectConfig: Cypress.A
getProjectMetadata: () => {
return {
root: defaultProjectConfig.root,
sourceRoot: defaultProjectConfig.root,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did this API change between majors? Should we check defaultProjectConfig.root ?? defaultProjectConfig.sourceRoot

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it didn't change, I believe it was just a mistake on our part.

sourceRoot: defaultProjectConfig.sourceRoot,
projectType: 'application',
}
},
Expand Down
66 changes: 66 additions & 0 deletions system-tests/projects/angular-custom-root/angular.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"version": 1,
"newProjectRoot": "projects",
"projects": {
"angular": {
"projectType": "application",
"root": "",
"sourceRoot": "ui",
"prefix": "app",
"architect": {
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/angular",
"index": "ui/index.html",
"main": "ui/main.ts",
"tsConfig": "tsconfig.app.json",
"inlineStyleLanguage": "scss",
"assets": [
"ui/favicon.ico"
],
"styles": [
"ui/styles.scss"
]
},
"configurations": {
"production": {
"outputHashing": "all"
},
"development": {
"buildOptimizer": false,
"optimization": false,
"vendorChunk": true,
"extractLicenses": false,
"sourceMap": true,
"namedChunks": true
}
},
"defaultConfiguration": "production"
},
"serve": {
"builder": "@angular-devkit/build-angular:dev-server",
"configurations": {
"production": {
"browserTarget": "angular:build:production"
},
"development": {
"browserTarget": "angular:build:development"
}
},
"defaultConfiguration": "development"
},
"extract-i18n": {
"builder": "@angular-devkit/build-angular:extract-i18n",
"options": {
"browserTarget": "angular:build"
}
}
}
}
},
"cli": {
"analytics": false
}
}
26 changes: 26 additions & 0 deletions system-tests/projects/angular-custom-root/cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { defineConfig } from 'cypress'

export default defineConfig({
component: {
devServer: {
framework: 'angular',
bundler: 'webpack',
webpackConfig: {
resolve: {
alias: {
'@angular/common': require.resolve('@angular/common'),
'@angular/core/testing': require.resolve('@angular/core/testing'),
'@angular/core': require.resolve('@angular/core'),
'@angular/platform-browser/testing': require.resolve('@angular/platform-browser/testing'),
'@angular/platform-browser': require.resolve('@angular/platform-browser'),
'@angular/platform-browser-dynamic/testing': require.resolve('@angular/platform-browser-dynamic/testing'),
'@angular/platform-browser-dynamic': require.resolve('@angular/platform-browser-dynamic'),
'zone.js/testing': require.resolve('zone.js/dist/zone-testing'),
'zone.js': require.resolve('zone.js'),
},
},
},
},
specPattern: '**/*.cy.ts',
},
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width,initial-scale=1.0">
<title>Components App</title>
</head>
<body>
<div data-cy-root></div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/// <reference types="cypress" />
import { mount } from 'cypress/angular'

declare global {
namespace Cypress {
interface Chainable {
mount: typeof mount
}
}
}

Cypress.Commands.add('mount', mount)

// Example use:
// cy.mount(MyComponent)
27 changes: 27 additions & 0 deletions system-tests/projects/angular-custom-root/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
"name": "angular",
"version": "0.0.0",
"private": true,
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development"
},
"dependencies": {
"@angular/common": "^15.0.3",
"@angular/compiler": "^15.0.3",
"@angular/core": "^15.0.3",
"@angular/platform-browser": "^15.0.3",
"@angular/platform-browser-dynamic": "^15.0.3",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.3",
"@angular/cli": "~15.0.3",
"@angular/compiler-cli": "^15.0.3",
"typescript": "~4.8.4"
}
}
13 changes: 13 additions & 0 deletions system-tests/projects/angular-custom-root/tsconfig.app.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "./out-tsc/app",
"types": []
},
"files": [
"ui/main.ts"
],
"include": [
"ui/**/*.d.ts"
]
}
33 changes: 33 additions & 0 deletions system-tests/projects/angular-custom-root/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/* To learn more about this file see: https://angular.io/config/tsconfig. */
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"forceConsistentCasingInFileNames": true,
"strict": true,
"noImplicitOverride": true,
"noPropertyAccessFromIndexSignature": true,
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"sourceMap": true,
"declaration": false,
"downlevelIteration": true,
"experimentalDecorators": true,
"moduleResolution": "node",
"importHelpers": true,
"target": "ES2022",
"module": "es2020",
"lib": [
"es2020",
"dom"
],
"useDefineForClassFields": false
},
"angularCompilerOptions": {
"enableI18nLegacyMessageIdFormat": false,
"strictInjectionParameters": true,
"strictInputAccessModifiers": true,
"strictTemplates": true
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { AppComponent } from './app.component'

describe('AppComponent', () => {
it('should mount', () => {
cy.mount(AppComponent)
cy.contains('h1', 'Hello World!')
})
})
14 changes: 14 additions & 0 deletions system-tests/projects/angular-custom-root/ui/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { Component } from '@angular/core'

@Component({
selector: 'app-root',
template: '<h1>{{message}}</h1>',
styles: [`
h1 {
background-color: blue;
color: white
}`],
})
export class AppComponent {
message = 'Hello World!'
}
11 changes: 11 additions & 0 deletions system-tests/projects/angular-custom-root/ui/app/app.module.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'

import { AppComponent } from './app.component'

@NgModule({
declarations: [AppComponent],
imports: [BrowserModule],
bootstrap: [AppComponent],
})
export class AppModule {}
Binary file not shown.
13 changes: 13 additions & 0 deletions system-tests/projects/angular-custom-root/ui/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Angular</title>
<base href="/">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="icon" type="image/x-icon" href="favicon.ico">
</head>
<body>
<app-root></app-root>
</body>
</html>
8 changes: 8 additions & 0 deletions system-tests/projects/angular-custom-root/ui/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need a basic Angular project in project-fixtures at some point, so we iterate over it like we do for React in system tests, testing against each supported major 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do have one, but this project felt different enough that I thought I'd make a new one. If I was to reuse the angular project-fixture, I'd have had to overwrite almost every file (every config file + the src code is in a different directory)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with @ZachJW34 that this is worth a different project since the source root is pretty fundamental part of the app.


import { AppModule } from './app/app.module'

import 'zone.js' // Included with Angular CLI.

platformBrowserDynamic().bootstrapModule(AppModule)
.catch((err) => console.error(err))
3 changes: 3 additions & 0 deletions system-tests/projects/angular-custom-root/ui/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
* {
box-sizing: border-box;
}
Loading