Skip to content

Commit

Permalink
simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kroeder committed Sep 28, 2019
1 parent 037db11 commit e187e79
Showing 1 changed file with 40 additions and 55 deletions.
95 changes: 40 additions & 55 deletions app/angular/src/server/__tests__/angular-cli_config.test.ts
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'],
},
},
});
},
});
});
});

0 comments on commit e187e79

Please sign in to comment.