-
Notifications
You must be signed in to change notification settings - Fork 11.9k
test(@angular/build): add unit tests for unit-test builder options #30766
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
Merged
+645
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
75 changes: 75 additions & 0 deletions
75
packages/angular/build/src/builders/unit-test/tests/options/browsers_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "browsers"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should use jsdom when browsers is not provided', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
browsers: undefined, | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ message: 'Using jsdom in Node.js for test execution.' }), | ||
); | ||
}); | ||
|
||
it('should fail when browsers is empty', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
browsers: [], | ||
}); | ||
|
||
await expectAsync(harness.executeOnce()).toBeRejectedWithError( | ||
/must NOT have fewer than 1 items/, | ||
); | ||
}); | ||
|
||
it('should launch a browser when provided', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
browsers: ['chrome'], | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ message: jasmine.stringMatching(/Starting browser "chrome"/) }), | ||
); | ||
}); | ||
|
||
it('should launch a browser in headless mode when specified', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
browsers: ['chromeheadless'], | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ | ||
message: jasmine.stringMatching(/Starting browser "chrome" in headless mode/), | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
63 changes: 63 additions & 0 deletions
63
packages/angular/build/src/builders/unit-test/tests/options/build-target_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "buildTarget"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should fail when buildTarget is not provided', async () => { | ||
const { buildTarget, ...rest } = BASE_OPTIONS; | ||
harness.useTarget('test', rest as any); | ||
|
||
await expectAsync(harness.executeOnce()).toBeRejectedWithError(/"buildTarget" is required/); | ||
}); | ||
|
||
it('should fail when buildTarget is empty', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
buildTarget: '', | ||
}); | ||
|
||
await expectAsync(harness.executeOnce()).toBeRejectedWithError( | ||
/must match "\^\S+:\S+(:\S+)?\$"/, | ||
); | ||
}); | ||
|
||
it('should fail when buildTarget does not have a project name', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
buildTarget: ':build', | ||
}); | ||
|
||
await expectAsync(harness.executeOnce()).toBeRejectedWithError( | ||
/must match "\^\S+:\S+(:\S+)?\$"/, | ||
); | ||
}); | ||
|
||
it('should fail when buildTarget does not have a target name', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
buildTarget: 'app:', | ||
}); | ||
|
||
await expectAsync(harness.executeOnce()).toBeRejectedWithError( | ||
/must match "\^\S+:\S+(:\S+)?\$"/, | ||
); | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/angular/build/src/builders/unit-test/tests/options/code-coverage-exclude_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "codeCoverageExclude"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
await harness.writeFiles({ | ||
'src/app/error.ts': `export const a = 1;`, | ||
}); | ||
}); | ||
|
||
it('should not exclude any files from coverage when not provided', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: true, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
const summary = harness.readFile('coverage/coverage-summary.json'); | ||
expect(summary).toContain('"src/app/error.ts"'); | ||
}); | ||
|
||
it('should exclude files from coverage that match the glob pattern', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: true, | ||
codeCoverageExclude: ['**/error.ts'], | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
const summary = harness.readFile('coverage/coverage-summary.json'); | ||
expect(summary).not.toContain('"src/app/error.ts"'); | ||
}); | ||
}); | ||
}); |
48 changes: 48 additions & 0 deletions
48
packages/angular/build/src/builders/unit-test/tests/options/code-coverage-reporters_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "codeCoverageReporters"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should generate a json summary report when specified', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: true, | ||
codeCoverageReporters: ['json-summary'] as any, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue(); | ||
}); | ||
|
||
it('should generate multiple reports when specified', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: true, | ||
codeCoverageReporters: ['json-summary', 'lcov'] as any, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(harness.hasFile('coverage/coverage-summary.json')).toBeTrue(); | ||
expect(harness.hasFile('coverage/lcov.info')).toBeTrue(); | ||
}); | ||
}); | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/angular/build/src/builders/unit-test/tests/options/code-coverage_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "codeCoverage"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should not generate a code coverage report when codeCoverage is false', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: false, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(harness.hasFile('coverage/index.html')).toBeFalse(); | ||
}); | ||
|
||
it('should generate a code coverage report when codeCoverage is true', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
codeCoverage: true, | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(harness.hasFile('coverage/index.html')).toBeTrue(); | ||
}); | ||
}); | ||
}); |
51 changes: 51 additions & 0 deletions
51
packages/angular/build/src/builders/unit-test/tests/options/debug_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "debug"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should not enter debug mode when debug is false', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
debug: false, | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(logs).not.toContain( | ||
jasmine.objectContaining({ message: jasmine.stringMatching(/Node.js inspector/) }), | ||
); | ||
}); | ||
|
||
it('should enter debug mode when debug is true', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
debug: true, | ||
}); | ||
|
||
const { result, logs } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
expect(logs).toContain( | ||
jasmine.objectContaining({ | ||
message: jasmine.stringMatching(/Node.js inspector is active/), | ||
}), | ||
); | ||
}); | ||
}); | ||
}); |
54 changes: 54 additions & 0 deletions
54
packages/angular/build/src/builders/unit-test/tests/options/providers-file_spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/** | ||
* @license | ||
* Copyright Google LLC All Rights Reserved. | ||
* | ||
* Use of this source code is governed by an MIT-style license that can be | ||
* found in the LICENSE file at https://angular.dev/license | ||
*/ | ||
|
||
import { execute } from '../../index'; | ||
import { | ||
BASE_OPTIONS, | ||
describeBuilder, | ||
UNIT_TEST_BUILDER_INFO, | ||
setupApplicationTarget, | ||
} from '../setup'; | ||
|
||
describeBuilder(execute, UNIT_TEST_BUILDER_INFO, (harness) => { | ||
xdescribe('Option: "providersFile"', () => { | ||
beforeEach(async () => { | ||
setupApplicationTarget(harness); | ||
}); | ||
|
||
it('should fail when providersFile does not exist', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
providersFile: 'src/my.providers.ts', | ||
}); | ||
|
||
const { result, error } = await harness.executeOnce({ outputLogsOnFailure: false }); | ||
expect(result).toBeUndefined(); | ||
expect(error?.message).toMatch( | ||
`The specified providers file "src/my.providers.ts" does not exist.`, | ||
); | ||
}); | ||
|
||
it('should use providers from the specified file', async () => { | ||
await harness.writeFiles({ | ||
'src/my.providers.ts': ` | ||
import { importProvidersFrom } from '@angular/core'; | ||
import { CommonModule } from '@angular/common'; | ||
export default [importProvidersFrom(CommonModule)]; | ||
`, | ||
}); | ||
|
||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
providersFile: 'src/my.providers.ts', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think
pending()
worked here without failing the test suite? IIRC that's what I used for the disabled tests for the karma-on-application-builder feature.