Skip to content

Commit c8951ab

Browse files
9kubczas4thePunderWoman
authored andcommitted
fix(docs-infra): remove config release from test scripts (angular#56062)
fix(docs-infra): remove config release from test scripts As we discussed in one of the previous PRs we should remove `--config=release` from test scripts on CI fix(docs-infra): use DI to inject current VERSION.major PR Close angular#56062
1 parent 0e2d80d commit c8951ab

File tree

7 files changed

+35
-13
lines changed

7 files changed

+35
-13
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Build adev in fast mode to ensure it continues to work
8989
run: yarn bazel build //adev:build --fast_adev --config=release
9090
- name: Run tests
91-
run: yarn bazel test //adev:test --config=release
91+
run: yarn bazel test //adev:test
9292

9393
publish-snapshots:
9494
runs-on:

.github/workflows/pr.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ jobs:
8888
- name: Build adev in fast mode to ensure it continues to work
8989
run: yarn bazel build //adev:build --fast_adev --config=release
9090
- name: Run tests
91-
run: yarn bazel test //adev:test --config=release
91+
run: yarn bazel test //adev:test
9292

9393
zone-js:
9494
runs-on:

adev/src/app/app.component.spec.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ import {AppComponent} from './app.component';
1111
import {provideRouter} from '@angular/router';
1212
import {routes} from './routes';
1313
import {Search, WINDOW} from '@angular/docs';
14+
import {CURRENT_MAJOR_VERSION} from './core/providers/current-version';
1415

1516
describe('AppComponent', () => {
1617
const fakeSearch = {};
1718
const fakeWindow = {location: {hostname: 'angular.dev'}};
19+
const fakeCurrentMajorVersion = 19;
1820

1921
it('should create the app', () => {
2022
TestBed.configureTestingModule({
@@ -28,6 +30,10 @@ describe('AppComponent', () => {
2830
provide: Search,
2931
useValue: fakeSearch,
3032
},
33+
{
34+
provide: CURRENT_MAJOR_VERSION,
35+
useValue: fakeCurrentMajorVersion,
36+
},
3137
],
3238
});
3339
const fixture = TestBed.createComponent(AppComponent);

adev/src/app/app.config.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import {
1212
ApplicationConfig,
1313
ENVIRONMENT_INITIALIZER,
1414
ErrorHandler,
15+
VERSION,
1516
inject,
1617
provideZoneChangeDetection,
1718
} from '@angular/core';
@@ -44,6 +45,7 @@ import {ExampleContentLoader} from './core/services/example-content-loader.servi
4445
import {ReuseTutorialsRouteStrategy} from './features/tutorial/tutorials-route-reuse-strategy';
4546
import {routes} from './routes';
4647
import {ReferenceScrollHandler} from './features/references/services/reference-scroll-handler.service';
48+
import {CURRENT_MAJOR_VERSION} from './core/providers/current-version';
4749

4850
export const appConfig: ApplicationConfig = {
4951
providers: [
@@ -71,6 +73,10 @@ export const appConfig: ApplicationConfig = {
7173
provideClientHydration(),
7274
provideHttpClient(withFetch()),
7375
provideAnimationsAsync(),
76+
{
77+
provide: CURRENT_MAJOR_VERSION,
78+
useValue: Number(VERSION.major),
79+
},
7480
{provide: ENVIRONMENT, useValue: environment},
7581
{
7682
provide: ENVIRONMENT_INITIALIZER,
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import {InjectionToken} from '@angular/core';
2+
3+
export const CURRENT_MAJOR_VERSION = new InjectionToken<number>('CURRENT_MAJOR_VERSION');

adev/src/app/core/services/version-manager.service.spec.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,11 @@ import {TestBed} from '@angular/core/testing';
1010

1111
import {INITIAL_ADEV_DOCS_VERSION, VersionManager} from './version-manager.service';
1212
import {WINDOW} from '@angular/docs';
13-
import {VERSION} from '@angular/core';
13+
import {CURRENT_MAJOR_VERSION} from '../providers/current-version';
1414

1515
describe('VersionManager', () => {
1616
const fakeWindow = {location: {hostname: 'angular.dev'}};
17+
const fakeCurrentMajorVersion = 19;
1718

1819
let service: VersionManager;
1920

@@ -24,6 +25,10 @@ describe('VersionManager', () => {
2425
provide: WINDOW,
2526
useValue: fakeWindow,
2627
},
28+
{
29+
provide: CURRENT_MAJOR_VERSION,
30+
useValue: fakeCurrentMajorVersion,
31+
},
2732
],
2833
});
2934
service = TestBed.inject(VersionManager);
@@ -33,18 +38,14 @@ describe('VersionManager', () => {
3338
expect(service).toBeTruthy();
3439
});
3540

36-
it('should receive major version', () => {
37-
expect(VERSION.major).not.toBe('0');
38-
});
39-
4041
it('should contain correct number of Angular Docs versions', () => {
4142
// Note: From v2 to v17 (inclusive), there were no v3
4243
const expectedAioDocsVersionsCount = 15;
4344

4445
// Last stable version and next
4546
const expectedRecentDocsVersionCount = 2;
4647

47-
const expectedPreviousAdevVersionsCount = Number(VERSION.major) - INITIAL_ADEV_DOCS_VERSION;
48+
const expectedPreviousAdevVersionsCount = fakeCurrentMajorVersion - INITIAL_ADEV_DOCS_VERSION;
4849

4950
expect(service['getAioVersions']().length).toBe(expectedAioDocsVersionsCount);
5051
expect(service['getRecentVersions']().length).toBe(expectedRecentDocsVersionCount);

adev/src/app/core/services/version-manager.service.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
* found in the LICENSE file at https://angular.dev/license
77
*/
88

9-
import {Injectable, VERSION, computed, inject, signal} from '@angular/core';
9+
import {Injectable, computed, inject, signal} from '@angular/core';
1010
import {VERSIONS_CONFIG} from '../constants/versions';
1111
import {WINDOW} from '@angular/docs';
12+
import {CURRENT_MAJOR_VERSION} from '../providers/current-version';
1213

1314
export interface Version {
1415
displayName: string;
@@ -26,6 +27,7 @@ export const MODE_PLACEHOLDER = '{{prefix}}';
2627
providedIn: 'root',
2728
})
2829
export class VersionManager {
30+
private readonly currentMajorVersion = inject(CURRENT_MAJOR_VERSION);
2931
private readonly window = inject(WINDOW);
3032

3133
// Note: We can assume that if the URL starts with v{{version}}, it is documentation for previous versions of Angular.
@@ -66,8 +68,8 @@ export class VersionManager {
6668
// version: 'rc',
6769
// },
6870
{
69-
url: this.getAdevDocsUrl(Number(VERSION.major)),
70-
displayName: this.getVersion(Number(VERSION.major)),
71+
url: this.getAdevDocsUrl(this.currentMajorVersion),
72+
displayName: this.getVersion(this.currentMajorVersion),
7173
version: this.currentVersionMode,
7274
},
7375
];
@@ -76,7 +78,11 @@ export class VersionManager {
7678
// List of Angular Docs versions hosted on angular.dev domain.
7779
private getAdevVersions(): Version[] {
7880
const adevVersions: Version[] = [];
79-
for (let version = Number(VERSION.major) - 1; version >= INITIAL_ADEV_DOCS_VERSION; version--) {
81+
for (
82+
let version = this.currentMajorVersion - 1;
83+
version >= INITIAL_ADEV_DOCS_VERSION;
84+
version--
85+
) {
8086
adevVersions.push({
8187
url: this.getAdevDocsUrl(version),
8288
displayName: this.getVersion(version),
@@ -102,7 +108,7 @@ export class VersionManager {
102108

103109
private getVersion(versionMode: VersionMode): string {
104110
if (versionMode === 'stable' || versionMode === 'deprecated') {
105-
return `v${VERSION.major}`;
111+
return `v${this.currentMajorVersion}`;
106112
}
107113
if (Number.isInteger(versionMode)) {
108114
return `v${versionMode}`;

0 commit comments

Comments
 (0)