-
-
Notifications
You must be signed in to change notification settings - Fork 9.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
40 additions
and
55 deletions.
There are no files selected for viewing
95 changes: 40 additions & 55 deletions
95
app/angular/src/server/__tests__/angular-cli_config.test.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 |
---|---|---|
@@ -1,67 +1,52 @@ | ||
import stripJsonComments from 'strip-json-comments'; | ||
import { Path } from '@angular-devkit/core'; | ||
import { getAngularCliWebpackConfigOptions } from '../angular-cli_config'; | ||
|
||
// eslint-disable-next-line global-require | ||
jest.mock('fs', () => require('../../../../../__mocks__/fs')); | ||
jest.mock('path', () => ({ | ||
join: (...args) => | ||
args[args.length - 1] === 'angular.json' | ||
? 'angular.json' | ||
: jest.requireActual('path').join(...args), | ||
resolve: (...args) => 'tsconfig.json', | ||
})); | ||
|
||
const angularJson = jest | ||
.requireActual('fs') | ||
.readFileSync(jest.requireActual('path').resolve(__dirname, 'angular.json'), 'utf8'); | ||
|
||
const setupFiles = (files: any) => { | ||
// eslint-disable-next-line no-underscore-dangle, global-require | ||
require('fs').__setMockFiles(files); | ||
}; | ||
import * as fs from 'fs'; | ||
import * as path from 'path'; | ||
import { | ||
getAngularCliWebpackConfigOptions, | ||
getLeadingAngularCliProject, | ||
} from '../angular-cli_config'; | ||
|
||
describe('angular-cli_config', () => { | ||
describe('getAngularCliWebpackConfigOptions()', () => { | ||
it('should return have empty `buildOptions.sourceMap` and `buildOptions.optimization` by default', () => { | ||
setupFiles({ 'angular.json': angularJson }); | ||
|
||
const config = getAngularCliWebpackConfigOptions('/' as Path); | ||
|
||
expect(config).toMatchObject({ | ||
buildOptions: { | ||
sourceMap: {}, | ||
optimization: {}, | ||
}, | ||
}); | ||
it('should return have empty `buildOptions.sourceMap` and `buildOptions.optimization` by default', () => { | ||
const config = getAngularCliWebpackConfigOptions(__dirname as Path); | ||
expect(config).toMatchObject({ | ||
buildOptions: { | ||
sourceMap: {}, | ||
optimization: {}, | ||
}, | ||
}); | ||
}); | ||
|
||
it('should use `storybook` project by default when project is defined', () => { | ||
// Lazy clone example angular json | ||
const overrideAngularJson = JSON.parse(stripJsonComments(angularJson)); | ||
// Add storybook project | ||
overrideAngularJson.projects.storybook = { | ||
architect: { | ||
build: { | ||
options: { | ||
assets: [], | ||
styles: ['custom/styles'], | ||
}, | ||
it('should use `storybook` project by default when `storybook` project is defined', () => { | ||
// Lazy clone example angular json | ||
const angularJson = fs.readFileSync(path.resolve(__dirname, 'angular.json'), 'utf8'); | ||
const angularJsonWithStorybookProject = JSON.parse(stripJsonComments(angularJson)); | ||
|
||
// Add storybook project | ||
angularJsonWithStorybookProject.projects.storybook = { | ||
architect: { | ||
build: { | ||
options: { | ||
assets: [], | ||
styles: ['custom/styles'], | ||
}, | ||
}, | ||
}; | ||
|
||
setupFiles({ 'angular.json': JSON.stringify(overrideAngularJson) }); | ||
|
||
const config = getAngularCliWebpackConfigOptions('/' as Path); | ||
|
||
// Assure configuration matches values from `storybook` project | ||
expect(config).toMatchObject({ | ||
buildOptions: { | ||
assets: [], | ||
styles: ['custom/styles'], | ||
}, | ||
}; | ||
|
||
const projectConfig = getLeadingAngularCliProject(angularJsonWithStorybookProject); | ||
|
||
// Assure configuration matches values from `storybook` project | ||
expect(projectConfig).toMatchObject({ | ||
architect: { | ||
build: { | ||
options: { | ||
assets: [], | ||
styles: ['custom/styles'], | ||
}, | ||
}, | ||
}); | ||
}, | ||
}); | ||
}); | ||
}); |