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

Commit 26f6db8

Browse files
committed
test(copy): added tests for copyConfigToWatchConfig
1 parent 8924704 commit 26f6db8

File tree

2 files changed

+59
-2
lines changed

2 files changed

+59
-2
lines changed

src/copy.spec.ts

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import * as copy from './copy';
2+
3+
import * as config from './util/config';
4+
5+
describe('copy task', () => {
6+
describe('copyConfigToWatchConfig', () => {
7+
it('should do something', () => {
8+
// arrange
9+
const context = { };
10+
const configFile = 'configFile';
11+
const sampleConfig: copy.CopyConfig = {
12+
copyAssets: {
13+
src: ['{{SRC}}/assets/**/*'],
14+
dest: '{{WWW}}/assets'
15+
},
16+
copyIndexContent: {
17+
src: ['{{SRC}}/index.html', '{{SRC}}/manifest.json', '{{SRC}}/service-worker.js'],
18+
dest: '{{WWW}}'
19+
},
20+
copyFonts: {
21+
src: ['{{ROOT}}/node_modules/ionicons/dist/fonts/**/*', '{{ROOT}}/node_modules/ionic-angular/fonts/**/*'],
22+
dest: '{{WWW}}/assets/fonts'
23+
},
24+
copyPolyfills: {
25+
src: ['{{ROOT}}/node_modules/ionic-angular/polyfills/polyfills.js'],
26+
dest: '{{BUILD}}'
27+
},
28+
someOtherOption: {
29+
src: ['{{ROOT}}/whatever'],
30+
dest: '{{BUILD}}'
31+
}
32+
};
33+
let combinedSource: string[] = [];
34+
Object.keys(sampleConfig).forEach(entry => combinedSource = combinedSource.concat(sampleConfig[entry].src));
35+
36+
spyOn(config, config.generateContext.name).and.returnValue(context);
37+
spyOn(config, config.getUserConfigFile.name).and.returnValue(configFile);
38+
spyOn(config, config.fillConfigDefaults.name).and.returnValue(sampleConfig);
39+
40+
// act
41+
const result = copy.copyConfigToWatchConfig(null);
42+
43+
// assert
44+
expect(config.generateContext).toHaveBeenCalledWith(null);
45+
expect(config.getUserConfigFile).toHaveBeenCalledWith(context, copy.taskInfo, '');
46+
expect(config.fillConfigDefaults).toHaveBeenCalledWith(configFile, copy.taskInfo.defaultConfigFile);
47+
(result.paths as string[]).forEach(glob => {
48+
expect(combinedSource.indexOf(glob)).not.toEqual(-1);
49+
});
50+
expect(result.callback).toBeDefined();
51+
expect(result.options).toBeDefined();
52+
});
53+
});
54+
});

src/copy.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { mkdirpSync } from 'fs-extra';
22
import { dirname as pathDirname, join as pathJoin, relative as pathRelative, resolve as pathResolve } from 'path';
33
import { Logger } from './logger/logger';
4-
import { fillConfigDefaults, getUserConfigFile, replacePathVars } from './util/config';
4+
import { fillConfigDefaults, generateContext, getUserConfigFile, replacePathVars } from './util/config';
55
import { emit, EventType } from './util/events';
66
import { generateGlobTasks, globAll, GlobObject, GlobResult } from './util/glob-util';
77
import { copyFileAsync, rimRafAsync, unlinkAsync } from './util/helpers';
@@ -241,6 +241,9 @@ function cleanConfigContent(dictionaryKeys: string[], copyConfig: CopyConfig, co
241241
}
242242

243243
export function copyConfigToWatchConfig(context: BuildContext): Watcher {
244+
if (!context) {
245+
context = generateContext(context);
246+
}
244247
const configFile = getUserConfigFile(context, taskInfo, '');
245248
const copyConfig: CopyConfig = fillConfigDefaults(configFile, taskInfo.defaultConfigFile);
246249
let results: GlobObject[] = [];
@@ -274,7 +277,7 @@ interface CopySrcToDestResult {
274277
errorMessage: string;
275278
}
276279

277-
const taskInfo: TaskInfo = {
280+
export const taskInfo: TaskInfo = {
278281
fullArg: '--copy',
279282
shortArg: '-y',
280283
envVar: 'IONIC_COPY',

0 commit comments

Comments
 (0)