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

Commit

Permalink
test(copy): added tests for copyConfigToWatchConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
danbucholtz committed Dec 14, 2016
1 parent 8924704 commit 26f6db8
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 2 deletions.
54 changes: 54 additions & 0 deletions src/copy.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import * as copy from './copy';

import * as config from './util/config';

describe('copy task', () => {
describe('copyConfigToWatchConfig', () => {
it('should do something', () => {
// arrange
const context = { };
const configFile = 'configFile';
const sampleConfig: copy.CopyConfig = {
copyAssets: {
src: ['{{SRC}}/assets/**/*'],
dest: '{{WWW}}/assets'
},
copyIndexContent: {
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
dest: '{{WWW}}'
},
copyFonts: {
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
dest: '{{WWW}}/assets/fonts'
},
copyPolyfills: {
src: ['{{ROOT}}/node_modules/ionic-angular/polyfills/polyfills.js'],
dest: '{{BUILD}}'
},
someOtherOption: {
src: ['{{ROOT}}/whatever'],
dest: '{{BUILD}}'
}
};
let combinedSource: string[] = [];
Object.keys(sampleConfig).forEach(entry => combinedSource = combinedSource.concat(sampleConfig[entry].src));

spyOn(config, config.generateContext.name).and.returnValue(context);
spyOn(config, config.getUserConfigFile.name).and.returnValue(configFile);
spyOn(config, config.fillConfigDefaults.name).and.returnValue(sampleConfig);

// act
const result = copy.copyConfigToWatchConfig(null);

// assert
expect(config.generateContext).toHaveBeenCalledWith(null);
expect(config.getUserConfigFile).toHaveBeenCalledWith(context, copy.taskInfo, '');
expect(config.fillConfigDefaults).toHaveBeenCalledWith(configFile, copy.taskInfo.defaultConfigFile);
(result.paths as string[]).forEach(glob => {
expect(combinedSource.indexOf(glob)).not.toEqual(-1);
});
expect(result.callback).toBeDefined();
expect(result.options).toBeDefined();
});
});
});
7 changes: 5 additions & 2 deletions src/copy.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { mkdirpSync } from 'fs-extra';
import { dirname as pathDirname, join as pathJoin, relative as pathRelative, resolve as pathResolve } from 'path';
import { Logger } from './logger/logger';
import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/config';
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars } from './util/config';
import { emit, EventType } from './util/events';
import { generateGlobTasks, globAll, GlobObject, GlobResult } from './util/glob-util';
import { copyFileAsync, rimRafAsync, unlinkAsync } from './util/helpers';
Expand Down Expand Up @@ -241,6 +241,9 @@ function cleanConfigContent(dictionaryKeys: string[], copyConfig: CopyConfig, co
}

export function copyConfigToWatchConfig(context: BuildContext): Watcher {
if (!context) {
context = generateContext(context);
}
const configFile = getUserConfigFile(context, taskInfo, '');
const copyConfig: CopyConfig = fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
let results: GlobObject[] = [];
Expand Down Expand Up @@ -274,7 +277,7 @@ interface CopySrcToDestResult {
errorMessage: string;
}

const taskInfo: TaskInfo = {
export const taskInfo: TaskInfo = {
fullArg: '--copy',
shortArg: '-y',
envVar: 'IONIC_COPY',
Expand Down

0 comments on commit 26f6db8

Please sign in to comment.