-
Notifications
You must be signed in to change notification settings - Fork 13.3k
chore(angular): test schematics and code-splitting #31401
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
base: main
Are you sure you want to change the base?
Changes from all commits
466de9b
d2052cb
0ef4de4
5b1ac7f
4c31a83
d4d9df9
0ec8487
1f03469
828ab0b
d0a13aa
1570284
23f56fe
e5206fb
9852c96
fdcac9e
b51a105
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| name: 'Test Ionic Angular Package' | ||
| description: 'Test Ionic Angular Package' | ||
| runs: | ||
| using: 'composite' | ||
| steps: | ||
| - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | ||
| with: | ||
| node-version: 24.x | ||
| - uses: ./.github/workflows/actions/download-archive | ||
| with: | ||
| name: ionic-core | ||
| path: ./core | ||
| filename: CoreBuild.zip | ||
| - uses: ./.github/workflows/actions/download-archive | ||
| with: | ||
| name: ionic-angular | ||
| path: ./packages/angular | ||
| filename: AngularBuild.zip | ||
| - name: 🕸️ Install Angular Dependencies | ||
| run: npm ci | ||
| shell: bash | ||
| working-directory: ./packages/angular | ||
| - name: 📐 Run Angular Package Tests | ||
| run: npm run test | ||
| shell: bash | ||
| working-directory: ./packages/angular | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| /** | ||
| * Validates that per-component imports let a bundler code-split Ionic components. | ||
| * Inspects `www/stats.json`, the esbuild metafile, to see which output chunk a | ||
| * component landed in. `ion-toggle` is used by only the home page, so it | ||
| * should not be bundled with the landing page. | ||
| * | ||
| * Build core and the angular package before running this test. | ||
| */ | ||
|
|
||
| const fs = require('fs-extra'); | ||
| const path = require('path'); | ||
| const { execSync } = require('node:child_process'); | ||
|
|
||
| const PROJECT_DIR = path.join(__dirname, '../test/code-split'); | ||
| const STATS_FILE = path.join(PROJECT_DIR, 'www/stats.json'); | ||
|
|
||
|
|
||
| function collectChunks(stats, startChunkName, chunkSet) | ||
| { | ||
| chunkSet.add(startChunkName); | ||
| const chunk = stats.outputs[startChunkName] | ||
| for (const imported of chunk.imports) { | ||
| if (imported.kind === "import-statement" && !chunkSet.has(imported.path)) { | ||
| collectChunks(stats, imported.path, chunkSet); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| function findChunksForPage(stats, page) { | ||
| const chunkSet = new Set(); | ||
|
|
||
| for (const [chunkName, chunkData] of Object.entries(stats.outputs || {})) { | ||
| if (chunkName.endsWith('.js')) { | ||
| const importFound = Object.keys(chunkData.inputs).some(input => input.endsWith(page)); | ||
| if (importFound) { | ||
| collectChunks(stats, chunkName, chunkSet); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| return chunkSet; | ||
| } | ||
|
|
||
| function hasComponentAsInput(stats, chunks, component) { | ||
| for (const chunk of chunks) { | ||
| for (const inputName of Object.keys(stats.outputs[chunk].inputs)) { | ||
| if (inputName.endsWith(component)) { | ||
| return true; | ||
| } | ||
| } | ||
| } | ||
| return false; | ||
| } | ||
|
|
||
| function main() { | ||
| try { | ||
| execSync('npm i', { cwd: PROJECT_DIR }); | ||
| execSync('./sync.sh', { cwd: PROJECT_DIR }); | ||
| execSync(`npm run build`, { cwd: PROJECT_DIR, stdio: 'inherit' }); | ||
|
|
||
| const stats = fs.readJsonSync(STATS_FILE); | ||
| const chunks = findChunksForPage(stats, 'landing.page.ts'); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The closure rewrite works. Both regressions fail against it now: importing The header half of last round's check didn't make it in though, and without it this can pass having measured nothing. When no output matches, |
||
|
|
||
| const splitComponent = 'ion-toggle.js'; | ||
| if (hasComponentAsInput(stats, chunks, splitComponent)) { | ||
| throw new Error(`${splitComponent} was not split from landing page.`); | ||
| } | ||
|
|
||
| console.log('✅ verified code-split'); | ||
| } catch (error) { | ||
| process.exitCode = 1; | ||
| console.error(error); | ||
| } | ||
| } | ||
|
|
||
| main(); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| const fs = require('fs-extra'); | ||
| const path = require('path'); | ||
| const { execSync } = require('node:child_process'); | ||
|
|
||
| const testName = 'schematics-test'; | ||
| const packageRootDir = path.join(__dirname, '..'); | ||
| const testDir = path.join(packageRootDir, testName); | ||
|
|
||
| try { | ||
| // Delete old packages | ||
| execSync(`rm -f *.tgz`, {cwd: packageRootDir}); | ||
|
|
||
| // Pack ionic-core | ||
| execSync(`npm pack ../../core`, {cwd: packageRootDir}); | ||
|
|
||
| // Pack ionic-angular | ||
| execSync(`npm pack`, {cwd: packageRootDir}); | ||
|
|
||
| // Create new Angular project | ||
| execSync(`npx ng new ${testName} --style css --ssr false --ai-config none`, {cwd: packageRootDir}); | ||
|
|
||
| // Install ionic-angular and core packages | ||
| execSync(`npx ng add --skip-confirmation ../ionic-angular-*`, {cwd: testDir}); | ||
|
OS-jacobbell marked this conversation as resolved.
|
||
| execSync(`npm install ../*.tgz --no-save`, {cwd: testDir}); | ||
|
|
||
| // Run build | ||
| execSync(`npm run build`, {cwd: testDir}); | ||
| } catch(error) { | ||
| console.log(error); | ||
| process.exitCode = 1; | ||
| } | ||
|
|
||
| fs.removeSync(testDir); | ||
| execSync(`rm -f *.tgz`, {cwd: packageRootDir}); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { IonModalToken } from '@ionic/angular/common'; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| # Angular E2E Test Apps | ||
|
|
||
| Refer to the [Angular Testing documentation](/docs/angular/testing.md) in order to build and run the test app. | ||
|
|
||
| # Code Split Test App | ||
|
|
||
| Refer to the "Testing Code Splitting" section in the [Angular Package README](/packages/angular/README.md). |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| # This file is used by the build system to adjust CSS and JS output to support the specified browsers below. | ||
| # For additional information regarding the format and rule options, please see: | ||
| # https://github.com/browserslist/browserslist#queries | ||
|
|
||
| # For the full list of supported browsers by the Angular framework, please see: | ||
| # https://angular.dev/reference/versions#browser-support | ||
|
|
||
| # You can see what browsers were selected by your queries by running: | ||
| # npx browserslist | ||
|
|
||
| Chrome >=107 | ||
| Firefox >=106 | ||
| Edge >=107 | ||
| Safari >=16.1 | ||
| iOS >=16.1 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # Editor configuration, see https://editorconfig.org | ||
| root = true | ||
|
|
||
| [*] | ||
| charset = utf-8 | ||
| indent_style = space | ||
| indent_size = 2 | ||
| insert_final_newline = true | ||
| trim_trailing_whitespace = true | ||
|
|
||
| [*.ts] | ||
| quote_type = single | ||
|
|
||
| [*.md] | ||
| max_line_length = off | ||
| trim_trailing_whitespace = false |
Uh oh!
There was an error while loading. Please reload this page.