-
Notifications
You must be signed in to change notification settings - Fork 12k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(@angular-devkit/build-angular): handle main field
- Loading branch information
Showing
3 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
51 changes: 51 additions & 0 deletions
51
packages/angular_devkit/build_angular/src/builders/karma/tests/options/main_spec.ts
This file contains 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, KARMA_BUILDER_INFO, describeKarmaBuilder } from '../setup'; | ||
|
||
describeKarmaBuilder(execute, KARMA_BUILDER_INFO, (harness, setupTarget) => { | ||
describe('Option: "main"', () => { | ||
beforeEach(async () => { | ||
await setupTarget(harness); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await harness.writeFiles({ | ||
'src/magic.ts': `Object.assign(globalThis, {MAGIC_IS_REAL: true});`, | ||
'src/magic.spec.ts': ` | ||
declare const MAGIC_IS_REAL: boolean; | ||
describe('Magic', () => { | ||
it('can be scientificially proven to be true', () => { | ||
expect(typeof MAGIC_IS_REAL).toBe('boolean'); | ||
}); | ||
});`, | ||
}); | ||
// Remove this test, we don't expect it to pass with our setup script. | ||
await harness.removeFile('src/app/app.component.spec.ts'); | ||
|
||
// Add src/magic.ts to tsconfig. | ||
interface TsConfig { | ||
files: string[]; | ||
} | ||
const tsConfig = JSON.parse(harness.readFile('src/tsconfig.spec.json')) as TsConfig; | ||
tsConfig.files.push('magic.ts'); | ||
await harness.writeFile('src/tsconfig.spec.json', JSON.stringify(tsConfig)); | ||
}); | ||
|
||
it('uses custom setup file', async () => { | ||
harness.useTarget('test', { | ||
...BASE_OPTIONS, | ||
main: './src/magic.ts', | ||
}); | ||
|
||
const { result } = await harness.executeOnce(); | ||
expect(result?.success).toBeTrue(); | ||
}); | ||
}); | ||
}); |