-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathtestInit.spec.js
117 lines (98 loc) · 5.37 KB
/
testInit.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
/*global describe, expect, it, beforeEach, spyOn*/
var cwd = process.cwd();
var fs = require('fs');
var path = require('path');
var initJspm = require('../src/init');
var normalPath = function(path){
return path.replace(/\\/g,'/');
};
describe('jspm plugin init', function(){
var files, jspm, client, emitter;
var basePath = path.resolve(__dirname, '..');
beforeEach(function(){
spyOn(fs, 'existsSync').and.returnValue(true);
files = [];
jspm = {
browser: 'custom_browser.js',
config: 'custom_config.js',
loadFiles: ['src/**/*.js',{pattern:'not-cached.js', nocache:true}, {pattern:'not-watched.js', watched:false}],
packages: 'custom_packages/',
serveFiles: ['testfile.js']
};
client = {};
emitter = {
on: function() {}
};
initJspm(files, basePath, jspm, client, emitter);
});
it('should add config.js to the top of the files array', function(){
expect(normalPath(files[4].pattern)).toEqual(normalPath(basePath + '/custom_config.js'));
expect(files[4].included).toEqual(true);
});
it('should add browser.js to the top of the files array', function(){
expect(normalPath(files[3].pattern)).toEqual(normalPath(basePath + '/custom_browser.js'));
expect(files[3].included).toEqual(true);
});
it('should support an array of config files', function() {
jspm.config = ['custom_config.js', 'another_config.js'];
files = [];
initJspm(files, basePath, jspm, client, emitter);
expect(normalPath(files[4].pattern)).toEqual(normalPath(basePath + '/custom_config.js'));
expect(normalPath(files[5].pattern)).toEqual(normalPath(basePath + '/another_config.js'));
});
it('should add adapter.js to the top of the files array', function(){
expect(normalPath(files[2].pattern)).toEqual(normalPath(basePath + '/src/adapter.js'));
expect(files[2].included).toEqual(true);
});
it('should add systemjs-polyfills to the top of the files array', function(){
expect(normalPath(files[1].pattern)).toEqual(normalPath(basePath + '/custom_packages/system-polyfills.src.js'));
expect(files[1].included).toEqual(true);
});
it('should not add systemjs-polyfills to the top of the files array if it does not exist', function(){
fs.existsSync.and.returnValue(false);
initJspm(files, basePath, jspm, client, emitter);
expect(normalPath(files[1].pattern)).not.toEqual(normalPath(basePath + '/custom_packages/system-polyfills.src.js'));
expect(files[1].included).toEqual(true);
});
it('should add systemjs to the top of the files array', function(){
expect(normalPath(files[0].pattern)).toEqual(normalPath(basePath + '/custom_packages/system.src.js'));
expect(files[0].included).toEqual(true);
});
it('should add files from jspm.beforeFiles to the beginning of the files array', function() {
jspm.beforeFiles = ['node_modules/promise-polyfill.js', 'other-polyfill.js'];
initJspm(files, basePath, jspm, client, emitter);
expect(normalPath(files[0].pattern)).toEqual(normalPath(basePath + '/node_modules/promise-polyfill.js'));
expect(files[0].included).toEqual(true);
expect(normalPath(files[1].pattern)).toEqual(normalPath(basePath + '/other-polyfill.js'));
expect(files[1].included).toEqual(true);
});
it('should add files from jspm.loadFiles to client.expandedFiles', function(){
expect(client.jspm.expandedFiles).toEqual(['src/adapter.js', 'src/init.js']);
});
it('should add files from jspm.serveFiles to the files array as served files', function(){
expect(normalPath(files[files.length - 2].pattern)).toEqual(normalPath(cwd + '/testfile.js'));
expect(files[files.length - 2].included).toEqual(false);
expect(files[files.length - 2].served).toEqual(true);
expect(files[files.length - 2].watched).toEqual(true);
});
it('should use the configured jspm_packages path and include it at the end of the files array', function(){
expect(normalPath(files[files.length - 1].pattern)).toEqual(normalPath(path.resolve(cwd, './custom_packages/!(system-polyfills.src.js|system.src.js)/**')));
expect(files[files.length - 1].included).toEqual(false);
expect(files[files.length - 1].served).toEqual(true);
expect(files[files.length - 1].watched).toEqual(false);
});
it('should assign true to nocache option to served files with nocache option in jspm.loadFiles', function(){
expect(normalPath(files[files.length - 4].pattern)).toEqual(normalPath(cwd + '/not-cached.js'));
expect(files[files.length - 4].included).toEqual(false);
expect(files[files.length - 4].served).toEqual(true);
expect(files[files.length - 4].watched).toEqual(true);
expect(files[files.length - 4].nocache).toEqual(true);
});
it('should respect watched flag when adding jspm.loadFiles to served files', function(){
expect(normalPath(files[files.length - 3].pattern)).toEqual(normalPath(cwd + '/not-watched.js'));
expect(files[files.length - 3].included).toEqual(false);
expect(files[files.length - 3].served).toEqual(true);
expect(files[files.length - 3].watched).toEqual(false);
expect(files[files.length - 3].nocache).toEqual(false);
});
});