Skip to content
This repository has been archived by the owner on May 1, 2020. It is now read-only.

Commit

Permalink
refactor(tests): interim commit for sharing test
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Dec 14, 2016
1 parent d6de413 commit d57e9c3
Show file tree
Hide file tree
Showing 18 changed files with 402 additions and 132 deletions.
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
},
"scripts": {
"build": "npm run clean && tsc && npm run sass",
"test-watch": "tsc --watch --target es2015",
"build-and-test": "npm run build && npm run test",
"changelog": "./node_modules/.bin/conventional-changelog -p angular -i CHANGELOG.md -s",
"clean": "rimraf ./dist",
Expand All @@ -26,8 +27,8 @@
"nightly": "npm run build && node ./scripts/publish-nightly.js",
"sass": "node-sass ./src/dev-client/sass/ion-dev.scss --output ./bin/ --output-style compressed",
"sass-watch": "npm run sass && node-sass ./src/dev-client/sass/ion-dev.scss --watch --output ./bin/ --output-style compressed",
"test": "jasmine JASMINE_CONFIG_PATH=src/spec/jasmine.config.json || true",
"watch": "npm run clean && tsc --watch & npm run sass-watch"
"test": "jasmine JASMINE_CONFIG_PATH=scripts/jasmine.config.json || true",
"watch": "npm run clean && & npm run sass-watch"
},
"main": "dist/index.js",
"dependencies": {
Expand Down Expand Up @@ -88,10 +89,11 @@
"jasmine": "2.5.2",
"mock-fs": "3.11.0",
"node-sass": "3.10.1",
"proxyquire": "^1.7.10",
"rimraf": "2.5.4",
"rxjs": "5.0.0-beta.12",
"tslint-ionic-rules": "0.0.8",
"typescript": "2.0.9",
"typescript": "^2.1.4",
"zone.js": "^0.6.26"
},
"peerDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"spec_dir": "dist/spec",
"spec_dir": "dist",
"spec_files": [
"**/*[sS]pec.js"
],
Expand Down
37 changes: 24 additions & 13 deletions src/spec/build.spec.ts → src/build.spec.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,18 @@
import { BuildContext } from '../util/interfaces';
/*import { BuildContext } from './util/interfaces';
import * as build from '../build';
import * as bundle from '../bundle';
import * as copy from '../copy';
import * as minify from '../minify';
import * as lint from '../lint';
import * as ngc from '../ngc';
import * as sass from '../sass';
import * as transpile from '../transpile';
import * as helpers from './util/helpers';
import * as build from './build';
import * as bundle from './bundle';
import * as copy from './copy';
import * as minify from './minify';
import * as lint from './lint';
import * as ngc from './ngc';
import * as sass from './sass';
import * as transpile from './transpile';
describe('build', () => {
beforeEach(() => {
spyOn(helpers, 'readFileAsync').and.returnValue(Promise.resolve());
spyOn(copy, 'copy').and.returnValue(Promise.resolve());
spyOn(ngc, 'ngc').and.returnValue(Promise.resolve());
spyOn(bundle, 'bundle').and.returnValue(Promise.resolve());
Expand All @@ -21,8 +23,7 @@ describe('build', () => {
spyOn(transpile, 'transpile').and.returnValue(Promise.resolve());
});
describe('build', () => {
it('isProd', () => {
it('should do a prod build', (done: Function) => {
let context: BuildContext = {
isProd: true,
optimizeJs: true,
Expand All @@ -32,6 +33,7 @@ describe('build', () => {
};
build.build(context).then(() => {
expect(helpers.readFileAsync).toHaveBeenCalled();
expect(copy.copy).toHaveBeenCalled();
expect(ngc.ngc).toHaveBeenCalled();
expect(bundle.bundle).toHaveBeenCalled();
Expand All @@ -41,10 +43,14 @@ describe('build', () => {
expect(lint.lint).toHaveBeenCalled();
expect(transpile.transpile).not.toHaveBeenCalled();
done();
}).catch(err => {
console.log(`err.message: `, err.message);
expect(true).toEqual(false);
});
});
it('isDev', () => {
it('should do a dev build', (done: Function) => {
let context: BuildContext = {
isProd: false,
optimizeJs: false,
Expand All @@ -54,6 +60,7 @@ describe('build', () => {
};
build.build(context).then(() => {
expect(helpers.readFileAsync).toHaveBeenCalled();
expect(copy.copy).toHaveBeenCalled();
expect(transpile.transpile).toHaveBeenCalled();
expect(bundle.bundle).toHaveBeenCalled();
Expand All @@ -63,8 +70,12 @@ describe('build', () => {
expect(ngc.ngc).not.toHaveBeenCalled();
expect(minify.minifyJs).not.toHaveBeenCalled();
expect(minify.minifyCss).not.toHaveBeenCalled();
done();
}).catch(err => {
console.log(`err.message: `, err.message);
expect(true).toEqual(false);
});
});
});
});
*/
1 change: 0 additions & 1 deletion src/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { sass, sassUpdate } from './sass';
import { templateUpdate } from './template';
import { transpile, transpileUpdate, transpileDiagnosticsOnly } from './transpile';


export function build(context: BuildContext) {
setContext(context);
const logger = new Logger(`build ${(context.isProd ? 'prod' : 'dev')}`);
Expand Down
214 changes: 214 additions & 0 deletions src/bundle.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
import * as bundle from './bundle';
import * as rollup from './rollup';
import * as webpack from './webpack';
import * as Constants from './util/constants';
import { ChangedFile } from './util/interfaces';

describe('bundle task', () => {

describe('bundle', () => {
it('should return the value rollup task returns', async (done: Function) => {
// arrange
spyOn(rollup, rollup.rollup.name).and.returnValue(Promise.resolve());
const context = { bundler: Constants.BUNDLER_ROLLUP};

// act
await bundle.bundle(context);

// assert
expect(rollup.rollup).toHaveBeenCalled();
done();
});

it('should throw when rollup throws', async (done: Function) => {
const errorText = 'simulating an error';
try {
// arrange
spyOn(rollup, rollup.rollup.name).and.throwError(errorText);
const context = { bundler: Constants.BUNDLER_ROLLUP};

// act
await bundle.bundle(context);
throw new Error('Should never happen');
} catch (ex) {
// assert
expect(rollup.rollup).toHaveBeenCalled();
expect(ex.message).toBe(errorText, `Received ${ex.message} instead of expected ${errorText}`);
done();
}
});

it('should return the value webpack task returns', async (done: Function) => {
// arrange
spyOn(webpack, webpack.webpack.name).and.returnValue(Promise.resolve());
const context = { bundler: Constants.BUNDLER_WEBPACK};

// act
await bundle.bundle(context);

// assert
expect(webpack.webpack).toHaveBeenCalled();
done();
});

it('should throw when rollup throws', async (done: Function) => {
const errorText = 'simulating an error';
try {
// arrange
spyOn(webpack, webpack.webpack.name).and.throwError(errorText);
const context = { bundler: Constants.BUNDLER_WEBPACK};

// act
await bundle.bundle(context);
throw new Error('Should never happen');
} catch (ex) {
// assert
expect(webpack.webpack).toHaveBeenCalled();
expect(ex.message).toBe(errorText, `Received ${ex.message} instead of expected ${errorText}`);
done();
}
});
});

describe('bundleUpdate', () => {
it('should return the value rollup returns', async (done: Function) => {
// arrange
spyOn(rollup, rollup.rollupUpdate.name).and.returnValue(Promise.resolve());
const context = { bundler: Constants.BUNDLER_ROLLUP};
const changedFiles: ChangedFile[] = [];

// act
await bundle.bundleUpdate(changedFiles, context);

// assert
expect(rollup.rollupUpdate).toHaveBeenCalledWith(changedFiles, context);
done();
});

it('should throw when rollup throws', async (done: Function) => {
const errorText = 'simulating an error';
try {
// arrange
spyOn(rollup, rollup.rollupUpdate.name).and.throwError(errorText);
const context = { bundler: Constants.BUNDLER_ROLLUP};
const changedFiles: ChangedFile[] = [];

// act
await bundle.bundleUpdate(changedFiles, context);
throw new Error('Should never happen');
} catch (ex) {
// assert
expect(rollup.rollupUpdate).toHaveBeenCalled();
expect(ex.message).toBe(errorText, `Received ${ex.message} instead of expected ${errorText}`);
done();
}
});

it('should return the value webpack returns', async (done: Function) => {
// arrange
spyOn(webpack, webpack.webpackUpdate.name).and.returnValue(Promise.resolve());
const context = { bundler: Constants.BUNDLER_WEBPACK};
const changedFiles: ChangedFile[] = [];

// act
await bundle.bundleUpdate(changedFiles, context);

// assert
expect(webpack.webpackUpdate).toHaveBeenCalledWith(changedFiles, context);
done();
});

it('should throw when webpack throws', async (done: Function) => {
const errorText = 'simulating an error';
try {
// arrange
spyOn(webpack, webpack.webpackUpdate.name).and.throwError(errorText);
const context = { bundler: Constants.BUNDLER_WEBPACK};
const changedFiles: ChangedFile[] = [];

// act
await bundle.bundleUpdate(changedFiles, context);
throw new Error('Should never happen');
} catch (ex) {
// assert
expect(webpack.webpackUpdate).toHaveBeenCalled();
expect(ex.message).toBe(errorText, `Received ${ex.message} instead of expected ${errorText}`);
done();
}
});
});

describe('buildJsSourceMaps', () => {
it('should get the value from the rollup config', () => {
// arrange
const config = {
sourceMap: true
};
spyOn(rollup, rollup.getRollupConfig.name).and.returnValue(config);
const context = { bundler: Constants.BUNDLER_ROLLUP};
// act
const result = bundle.buildJsSourceMaps(context);

// assert
expect(rollup.getRollupConfig).toHaveBeenCalledWith(context, null);
expect(result).toEqual(config.sourceMap, `Expected result ${result} to equal ${config.sourceMap}`);
});

it('should get false when devtool is null for webpack', () => {
// arrange
const config = { };
spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
const context = { bundler: Constants.BUNDLER_WEBPACK};
// act
const result = bundle.buildJsSourceMaps(context);

// assert
expect(webpack.getWebpackConfig).toHaveBeenCalledWith(context, null);
expect(result).toEqual(false, `Expected result ${result} to equal false`);
});

it('should get false when devtool is valid', () => {
// arrange
const config = { devtool: 'someValue'};
spyOn(webpack, webpack.getWebpackConfig.name).and.returnValue(config);
const context = { bundler: Constants.BUNDLER_WEBPACK};
// act
const result = bundle.buildJsSourceMaps(context);

// assert
expect(webpack.getWebpackConfig).toHaveBeenCalledWith(context, null);
expect(result).toEqual(true, `Expected result ${result} to equal true`);
});
});

describe('getJsOutputDest', () => {
it('should get the value from rollup', () => {
// arrange
const config = { };
const returnValue = 'someString';
spyOn(rollup, rollup.getRollupConfig.name).and.returnValue(config);
spyOn(rollup, rollup.getOutputDest.name).and.returnValue(returnValue);
const context = { bundler: Constants.BUNDLER_ROLLUP};
// act
const result = bundle.getJsOutputDest(context);

// assert
expect(rollup.getRollupConfig).toHaveBeenCalledWith(context, null);
expect(rollup.getOutputDest).toHaveBeenCalledWith(context, config);
expect(result).toEqual(returnValue, `Expected result ${result} to equal ${returnValue}`);
});

it('should get the value from webpack', () => {
// arrange
const returnValue = 'someString';
spyOn(webpack, webpack.getOutputDest.name).and.returnValue(returnValue);
const context = { bundler: Constants.BUNDLER_WEBPACK};
// act
const result = bundle.getJsOutputDest(context);

// assert
expect(webpack.getOutputDest).toHaveBeenCalledWith(context);
expect(result).toEqual(returnValue, `Expected result ${result} to equal ${returnValue}`);
});
});
});
Loading

0 comments on commit d57e9c3

Please sign in to comment.