Skip to content

Commit 7c36118

Browse files
authored
fix: use srcRoot for angular build context (#25090)
1 parent 3617aaf commit 7c36118

17 files changed

+5797
-1
lines changed

npm/webpack-dev-server/src/helpers/angularHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ function createFakeContext (projectRoot: string, defaultProjectConfig: Cypress.A
217217
getProjectMetadata: () => {
218218
return {
219219
root: defaultProjectConfig.root,
220-
sourceRoot: defaultProjectConfig.root,
220+
sourceRoot: defaultProjectConfig.sourceRoot,
221221
projectType: 'application',
222222
}
223223
},
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"version": 1,
4+
"newProjectRoot": "projects",
5+
"projects": {
6+
"angular": {
7+
"projectType": "application",
8+
"root": "",
9+
"sourceRoot": "ui",
10+
"prefix": "app",
11+
"architect": {
12+
"build": {
13+
"builder": "@angular-devkit/build-angular:browser",
14+
"options": {
15+
"outputPath": "dist/angular",
16+
"index": "ui/index.html",
17+
"main": "ui/main.ts",
18+
"tsConfig": "tsconfig.app.json",
19+
"inlineStyleLanguage": "scss",
20+
"assets": [
21+
"ui/favicon.ico"
22+
],
23+
"styles": [
24+
"ui/styles.scss"
25+
]
26+
},
27+
"configurations": {
28+
"production": {
29+
"outputHashing": "all"
30+
},
31+
"development": {
32+
"buildOptimizer": false,
33+
"optimization": false,
34+
"vendorChunk": true,
35+
"extractLicenses": false,
36+
"sourceMap": true,
37+
"namedChunks": true
38+
}
39+
},
40+
"defaultConfiguration": "production"
41+
},
42+
"serve": {
43+
"builder": "@angular-devkit/build-angular:dev-server",
44+
"configurations": {
45+
"production": {
46+
"browserTarget": "angular:build:production"
47+
},
48+
"development": {
49+
"browserTarget": "angular:build:development"
50+
}
51+
},
52+
"defaultConfiguration": "development"
53+
},
54+
"extract-i18n": {
55+
"builder": "@angular-devkit/build-angular:extract-i18n",
56+
"options": {
57+
"browserTarget": "angular:build"
58+
}
59+
}
60+
}
61+
}
62+
},
63+
"cli": {
64+
"analytics": false
65+
}
66+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { defineConfig } from 'cypress'
2+
3+
export default defineConfig({
4+
component: {
5+
devServer: {
6+
framework: 'angular',
7+
bundler: 'webpack',
8+
webpackConfig: {
9+
resolve: {
10+
alias: {
11+
'@angular/common': require.resolve('@angular/common'),
12+
'@angular/core/testing': require.resolve('@angular/core/testing'),
13+
'@angular/core': require.resolve('@angular/core'),
14+
'@angular/platform-browser/testing': require.resolve('@angular/platform-browser/testing'),
15+
'@angular/platform-browser': require.resolve('@angular/platform-browser'),
16+
'@angular/platform-browser-dynamic/testing': require.resolve('@angular/platform-browser-dynamic/testing'),
17+
'@angular/platform-browser-dynamic': require.resolve('@angular/platform-browser-dynamic'),
18+
'zone.js/testing': require.resolve('zone.js/dist/zone-testing'),
19+
'zone.js': require.resolve('zone.js'),
20+
},
21+
},
22+
},
23+
},
24+
specPattern: '**/*.cy.ts',
25+
},
26+
})
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<meta charset="utf-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width,initial-scale=1.0">
7+
<title>Components App</title>
8+
</head>
9+
<body>
10+
<div data-cy-root></div>
11+
</body>
12+
</html>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/// <reference types="cypress" />
2+
import { mount } from 'cypress/angular'
3+
4+
declare global {
5+
namespace Cypress {
6+
interface Chainable {
7+
mount: typeof mount
8+
}
9+
}
10+
}
11+
12+
Cypress.Commands.add('mount', mount)
13+
14+
// Example use:
15+
// cy.mount(MyComponent)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"name": "angular",
3+
"version": "0.0.0",
4+
"private": true,
5+
"scripts": {
6+
"ng": "ng",
7+
"start": "ng serve",
8+
"build": "ng build",
9+
"watch": "ng build --watch --configuration development"
10+
},
11+
"dependencies": {
12+
"@angular/common": "^15.0.3",
13+
"@angular/compiler": "^15.0.3",
14+
"@angular/core": "^15.0.3",
15+
"@angular/platform-browser": "^15.0.3",
16+
"@angular/platform-browser-dynamic": "^15.0.3",
17+
"rxjs": "~7.5.0",
18+
"tslib": "^2.3.0",
19+
"zone.js": "~0.11.4"
20+
},
21+
"devDependencies": {
22+
"@angular-devkit/build-angular": "^15.0.3",
23+
"@angular/cli": "~15.0.3",
24+
"@angular/compiler-cli": "^15.0.3",
25+
"typescript": "~4.8.4"
26+
}
27+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "./tsconfig.json",
3+
"compilerOptions": {
4+
"outDir": "./out-tsc/app",
5+
"types": []
6+
},
7+
"files": [
8+
"ui/main.ts"
9+
],
10+
"include": [
11+
"ui/**/*.d.ts"
12+
]
13+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/* To learn more about this file see: https://angular.io/config/tsconfig. */
2+
{
3+
"compileOnSave": false,
4+
"compilerOptions": {
5+
"baseUrl": "./",
6+
"outDir": "./dist/out-tsc",
7+
"forceConsistentCasingInFileNames": true,
8+
"strict": true,
9+
"noImplicitOverride": true,
10+
"noPropertyAccessFromIndexSignature": true,
11+
"noImplicitReturns": true,
12+
"noFallthroughCasesInSwitch": true,
13+
"sourceMap": true,
14+
"declaration": false,
15+
"downlevelIteration": true,
16+
"experimentalDecorators": true,
17+
"moduleResolution": "node",
18+
"importHelpers": true,
19+
"target": "ES2022",
20+
"module": "es2020",
21+
"lib": [
22+
"es2020",
23+
"dom"
24+
],
25+
"useDefineForClassFields": false
26+
},
27+
"angularCompilerOptions": {
28+
"enableI18nLegacyMessageIdFormat": false,
29+
"strictInjectionParameters": true,
30+
"strictInputAccessModifiers": true,
31+
"strictTemplates": true
32+
}
33+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AppComponent } from './app.component'
2+
3+
describe('AppComponent', () => {
4+
it('should mount', () => {
5+
cy.mount(AppComponent)
6+
cy.contains('h1', 'Hello World!')
7+
})
8+
})
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Component } from '@angular/core'
2+
3+
@Component({
4+
selector: 'app-root',
5+
template: '<h1>{{message}}</h1>',
6+
styles: [`
7+
h1 {
8+
background-color: blue;
9+
color: white
10+
}`],
11+
})
12+
export class AppComponent {
13+
message = 'Hello World!'
14+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import { NgModule } from '@angular/core'
2+
import { BrowserModule } from '@angular/platform-browser'
3+
4+
import { AppComponent } from './app.component'
5+
6+
@NgModule({
7+
declarations: [AppComponent],
8+
imports: [BrowserModule],
9+
bootstrap: [AppComponent],
10+
})
11+
export class AppModule {}
Binary file not shown.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<!doctype html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="utf-8">
5+
<title>Angular</title>
6+
<base href="/">
7+
<meta name="viewport" content="width=device-width, initial-scale=1">
8+
<link rel="icon" type="image/x-icon" href="favicon.ico">
9+
</head>
10+
<body>
11+
<app-root></app-root>
12+
</body>
13+
</html>
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic'
2+
3+
import { AppModule } from './app/app.module'
4+
5+
import 'zone.js' // Included with Angular CLI.
6+
7+
platformBrowserDynamic().bootstrapModule(AppModule)
8+
.catch((err) => console.error(err))
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
* {
2+
box-sizing: border-box;
3+
}

0 commit comments

Comments
 (0)