Skip to content

Commit 64c0f45

Browse files
mike-plummerZachJW34
andauthoredSep 15, 2022
fix: Fix missing it.skip function in Angular tests (#23829)
* fix: restore mocha methods * Simplify `it.skip` patch, add tests * Consolidate test runs for perf * Add tests to validate `skip` and `only` behaviors Co-authored-by: Zachary Williams <zachjw34@gmail.com>
1 parent 6ee305b commit 64c0f45

File tree

4 files changed

+192
-1
lines changed

4 files changed

+192
-1
lines changed
 

‎npm/angular/src/mount.ts

+5
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,11 @@ export type MountResponse<T> = {
9494
component: T
9595
};
9696

97+
// 'zone.js/testing' is not properly aliasing `it.skip` but it does provide `xit`/`xspecify`
98+
// Written up under https://github.com/angular/angular/issues/46297 but is not seeing movement
99+
// so we'll patch here pending a fix in that library
100+
globalThis.it.skip = globalThis.xit
101+
97102
/**
98103
* Bootstraps the TestModuleMetaData passed to the TestBed
99104
*
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import { AppComponent } from './app.component'
2+
3+
const ExcludedTestTitle = 'should not exist'
4+
5+
// Validating Mocha syntax and behavior of *.only is still valid after being patched by `zone.js/testing`
6+
// Github Issue: https://github.com/cypress-io/cypress/issues/23409
7+
describe('only', () => {
8+
context.only('01 - executions', () => {
9+
describe('suite', () => {
10+
suite.only('should exist on "suite"', () => {
11+
it('succeeds', () => {})
12+
})
13+
14+
it(ExcludedTestTitle, () => {})
15+
})
16+
17+
describe('describe', () => {
18+
describe.only('should exist on "describe"', () => {
19+
it('succeeds', () => {})
20+
})
21+
22+
it(ExcludedTestTitle, () => {})
23+
})
24+
25+
describe('context', () => {
26+
context.only('should exist on "context"', () => {
27+
it('succeeds', () => {})
28+
})
29+
30+
it(ExcludedTestTitle, () => {})
31+
})
32+
33+
describe('specify', () => {
34+
specify.only('should exist on "specify"', () => {})
35+
it(ExcludedTestTitle, () => {})
36+
})
37+
38+
describe('test', () => {
39+
test.only('should exist on "test"', () => {})
40+
it(ExcludedTestTitle, () => {})
41+
})
42+
43+
describe('it', () => {
44+
it.only('should exist on "it"', () => {})
45+
it(ExcludedTestTitle, () => {})
46+
})
47+
})
48+
49+
context.only('02 - validations', () => {
50+
const verifyNotPresent = (title: string) => {
51+
cy.wrap(Cypress.$(window.top!.document.body)).within(() =>
52+
cy
53+
.contains(title)
54+
.should('not.exist')
55+
)
56+
}
57+
58+
describe('suite', () => {
59+
it('should not include other test', () => {
60+
verifyNotPresent(ExcludedTestTitle)
61+
})
62+
})
63+
64+
describe('describe', () => {
65+
it('should not include other test', () => {
66+
verifyNotPresent(ExcludedTestTitle)
67+
})
68+
})
69+
70+
describe('context', () => {
71+
it('should not include other test', () => {
72+
verifyNotPresent(ExcludedTestTitle)
73+
})
74+
})
75+
76+
describe('specify', () => {
77+
it('should not include other test', () => {
78+
verifyNotPresent(ExcludedTestTitle)
79+
})
80+
})
81+
82+
describe('test', () => {
83+
it('should not include other test', () => {
84+
verifyNotPresent(ExcludedTestTitle)
85+
})
86+
})
87+
88+
describe('it', () => {
89+
it('should not include other test', () => {
90+
verifyNotPresent(ExcludedTestTitle)
91+
})
92+
})
93+
})
94+
})
95+
96+
it('empty passing test', () => {})
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
import { AppComponent } from './app.component'
2+
3+
// Validating Mocha syntax and behavior of *.skip is still valid after being patched by `zone.js/testing`
4+
// Github Issue: https://github.com/cypress-io/cypress/issues/23409
5+
describe('skip', () => {
6+
context('01 - executions', () => {
7+
describe('suite', () => {
8+
suite.skip('should exist on "suite"', () => {
9+
it('skipped', () => {})
10+
})
11+
})
12+
13+
describe('describe', () => {
14+
describe.skip('should exist on "describe"', () => {
15+
it('skipped', () => {})
16+
})
17+
})
18+
19+
describe('context', () => {
20+
context.skip('should exist on "context"', () => {
21+
it('skipped', () => {})
22+
})
23+
})
24+
25+
describe('specify', () => {
26+
specify.skip('should exist on "specify"', () => {})
27+
})
28+
29+
describe('test', () => {
30+
test.skip('should exist on "test"', () => {})
31+
})
32+
33+
describe('it', () => {
34+
it.skip('should exist on "it"', () => {})
35+
})
36+
})
37+
38+
context('02 - validations', () => {
39+
const verifyWasSkipped = (title: string) => {
40+
cy.wrap(Cypress.$(window.top!.document.body)).within(() =>
41+
cy
42+
.contains(title)
43+
.parents('[data-model-state="pending"]') // Find parent row with class indicating test was skipped
44+
.should('be.visible')
45+
)
46+
}
47+
48+
describe('suite', () => {
49+
it('should have been skipped', () => {
50+
verifyWasSkipped('should exist on "suite"')
51+
})
52+
})
53+
54+
describe('describe', () => {
55+
it('should have been skipped', () => {
56+
verifyWasSkipped('should exist on "describe"')
57+
})
58+
})
59+
60+
describe('context', () => {
61+
it('should have been skipped', () => {
62+
verifyWasSkipped('should exist on "context"')
63+
})
64+
})
65+
66+
describe('specify', () => {
67+
it('should have been skipped', () => {
68+
verifyWasSkipped('should exist on "specify"')
69+
})
70+
})
71+
72+
describe('test', () => {
73+
it('should have been skipped', () => {
74+
verifyWasSkipped('should exist on "test"')
75+
})
76+
})
77+
78+
describe('it', () => {
79+
it('should have been skipped', () => {
80+
verifyWasSkipped('should exist on "it"')
81+
})
82+
})
83+
})
84+
})
85+
86+
it('empty passing test', () => {})

‎system-tests/test/component_testing_spec.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,11 @@ describe(`Angular CLI major versions`, () => {
113113
systemTests.setup()
114114

115115
for (const majorVersion of ANGULAR_MAJOR_VERSIONS) {
116-
const spec = `${majorVersion === '14' ? 'src/app/components/standalone.component.cy.ts,src/app/mount.cy.ts' : 'src/app/mount.cy.ts'}`
116+
let spec = 'src/**/*.cy.ts'
117+
118+
if (majorVersion === '13') {
119+
spec = `${spec},!src/app/components/standalone.component.cy.ts`
120+
}
117121

118122
systemTests.it(`v${majorVersion} with mount tests`, {
119123
project: `angular-${majorVersion}`,

0 commit comments

Comments
 (0)