Skip to content

Commit

Permalink
fix(webpack-dev-server): handle polyfills array for upcoming angular …
Browse files Browse the repository at this point in the history
…15 change (#24064)

Co-authored-by: Zachary Williams <[email protected]>
  • Loading branch information
Coly010 and ZachJW34 authored Oct 3, 2022
1 parent e626679 commit 0976034
Show file tree
Hide file tree
Showing 8 changed files with 5,887 additions and 5 deletions.
2 changes: 1 addition & 1 deletion npm/webpack-dev-server/cypress/e2e/angular.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/// <reference path="../support/e2e.ts" />
import type { ProjectFixtureDir } from '@tooling/system-tests/lib/fixtureDirs'

const WEBPACK_REACT: ProjectFixtureDir[] = ['angular-13', 'angular-14']
const WEBPACK_REACT: ProjectFixtureDir[] = ['angular-13', 'angular-14', 'angular-15']

// Add to this list to focus on a particular permutation
const ONLY_PROJECTS: ProjectFixtureDir[] = []
Expand Down
12 changes: 9 additions & 3 deletions npm/webpack-dev-server/src/helpers/angularHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,11 @@ export async function generateTsConfig (devServerConfig: AngularWebpackDevServer
}

if (buildOptions.polyfills) {
const polyfills = getProjectFilePath(buildOptions.polyfills)
const polyfills = Array.isArray(buildOptions.polyfills)
? buildOptions.polyfills.filter((p: string) => devServerConfig.options?.projectConfig.sourceRoot && p.startsWith(devServerConfig.options?.projectConfig.sourceRoot))
: [buildOptions.polyfills]

includePaths.push(polyfills)
includePaths.push(...polyfills.map((p: string) => getProjectFilePath(p)))
}

const cypressTypes = getProjectFilePath('node_modules', 'cypress', 'types', 'index.d.ts')
Expand Down Expand Up @@ -202,7 +204,11 @@ export async function getAngularJson (projectRoot: string): Promise<AngularJson>

function createFakeContext (projectRoot: string, defaultProjectConfig: Cypress.AngularDevServerProjectConfig) {
const logger = {
createChild: () => ({}),
createChild: () => {
return {
warn: () => {},
}
},
}

const context = {
Expand Down
27 changes: 27 additions & 0 deletions npm/webpack-dev-server/test/handlers/angularHandler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,33 @@ describe('angularHandler', function () {
expectLoadsAngularBuildOptions(buildOptions)
})

it('sources the config from angular-15', async () => {
const projectRoot = await scaffoldMigrationProject('angular-15')

process.chdir(projectRoot)

const devServerConfig = {
cypressConfig: {
projectRoot,
specPattern: 'src/**/*.cy.ts',
} as Cypress.PluginConfigOptions,
framework: 'angular',
} as AngularWebpackDevServerConfig

const { frameworkConfig: webpackConfig, sourceWebpackModulesResult } = await angularHandler(devServerConfig)

expect(webpackConfig).to.exist
expect((webpackConfig?.entry as any).main).to.be.undefined
expect(sourceWebpackModulesResult.framework?.importPath).to.include(path.join('@angular-devkit', 'build-angular'))

const { buildOptions } = await expectNormalizeProjectConfig(projectRoot)

await expectLoadsAngularJson(projectRoot)
await expectLoadsAngularCLiModules(projectRoot)
await expectGeneratesTsConfig(devServerConfig, buildOptions)
expectLoadsAngularBuildOptions(buildOptions)
})

it('allows custom project config', async () => {
const customProjectConfig = {
root: '',
Expand Down
31 changes: 31 additions & 0 deletions system-tests/projects/angular-15/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"name": "angular-15",
"version": "0.0.0",
"private": true,
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"watch": "ng build --watch --configuration development"
},
"dependencies": {
"@angular/animations": "^15.0.0-next.4",
"@angular/common": "^15.0.0-next.4",
"@angular/compiler": "^15.0.0-next.4",
"@angular/core": "^15.0.0-next.4",
"@angular/forms": "^15.0.0-next.4",
"@angular/platform-browser": "^15.0.0-next.4",
"@angular/platform-browser-dynamic": "^15.0.0-next.4",
"@angular/router": "^15.0.0-next.4",
"rxjs": "~7.5.0",
"tslib": "^2.3.0",
"zone.js": "~0.11.4"
},
"devDependencies": {
"@angular-devkit/build-angular": "^15.0.0-next.3",
"@angular/cli": "~15.0.0-next.3",
"@angular/compiler-cli": "^15.0.0-next.4",
"typescript": "~4.8.4"
},
"projectFixtureDirectory": "angular"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { StandaloneComponent } from './standalone.component'

describe('StandaloneComponent', () => {
it('can mount a standalone component', () => {
cy.mount(StandaloneComponent, {
componentProperties: {
name: 'Angular',
},
})

cy.get('h1').contains('Hello Angular')
})

it('can mount a standalone component using template', () => {
cy.mount('<app-standalone name="Angular"></app-standalone>', {
imports: [StandaloneComponent],
})

cy.get('h1').contains('Hello Angular')
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component, Input } from '@angular/core'

@Component({
standalone: true,
selector: 'app-standalone',
template: `<h1>Hello {{ name }}</h1>`,
})
export class StandaloneComponent {
@Input() name!: string
}
Loading

1 comment on commit 0976034

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 0976034 Oct 3, 2022

Choose a reason for hiding this comment

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

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release platform-specific build at https://on.cypress.io/installing-cypress#Install-pre-release-version.

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/10.10.0/linux-x64/develop-097603422535f88aed56b651824d0a3a9d5e81ff/cypress.tgz

Please sign in to comment.