UNPKG

3.63 kBPlain TextView Raw
1import { expect } from 'chai';
2import {
3 isSystem,
4 isSystemJS,
5 readConfig,
6 serializeConfig
7} from '../lib/config-serializer';
8
9describe('Config Serializer', () => {
10 let inpCfg = 'System.config({ defaultJSExtensions: true })';
11
12 it('reads configuration from the config file', () => {
13 let cfg = readConfig([inpCfg]);
14 expect(cfg.defaultJSExtensions).to.be.true;
15 });
16
17 it('can read configuration from SystemJS', () => {
18 let systemJSCfg = 'SystemJS.config({ defaultJSExtensions: true })';
19 let cfg = readConfig([systemJSCfg]);
20 expect(cfg.defaultJSExtensions).to.be.true;
21 });
22
23 it('reads config from multiple files', () => {
24 let inpCfg = 'System.config({ defaultJSExtensions: true })';
25 let inpCfg2 = 'System.config({ baseURL : "abc" })';
26 let cfg = readConfig([inpCfg, inpCfg2]);
27 expect(cfg.defaultJSExtensions).to.be.true;
28 expect(cfg.baseURL).to.be.equal('abc');
29 });
30
31 describe('Multiple config calls', () => {
32 it('reads config from single file', () => {
33 let inpCfg = `
34SystemJS.config({
35 packages: {
36 "aurelia-animator-css": {
37 "map": {
38 "aurelia-metadata": "npm:aurelia-metadata@1.0.3",
39 }
40 }
41 }
42});
43SystemJS.config({
44 packages: {
45 "siopa-skeleton": {
46 "format": "amd"
47 }
48 }
49})`;
50
51 let cfg = readConfig([inpCfg]);
52 expect(cfg.packages['aurelia-animator-css'].map['aurelia-metadata']).to.be.equal('npm:aurelia-metadata@1.0.3');
53 expect(cfg.packages['siopa-skeleton'].format).to.be.equal('amd');
54 });
55
56 it('should extend the config not orverrite it', () => {
57 let inpCfg = 'System.config({ defaultJSExtensions: true }); System.config({ baseURL : "abc" })';
58 let cfg = readConfig([inpCfg]);
59 expect(cfg.defaultJSExtensions).to.be.true;
60 expect(cfg.baseURL).to.be.equal('abc');
61 });
62 });
63
64 it('can serialize updated configuration', () => {
65 let cfg = readConfig([inpCfg]);
66 let outCfg =
67 `System.config({
68 defaultJSExtensions: true,
69 bundles: {
70 "app-bundle.js": [
71 "app/boot",
72 "app/main"
73 ]
74 }
75});`;
76
77 cfg.bundles = {
78 'app-bundle.js': [
79 'app/boot',
80 'app/main'
81 ]
82 };
83
84 let str = serializeConfig(cfg);
85 expect(str).to.be.equal(outCfg);
86 });
87
88 it('can serialize System configuration', () => {
89 let cfg = readConfig([inpCfg]);
90 let str = serializeConfig(cfg);
91 let outCfg =
92 `System.config({
93 defaultJSExtensions: true
94});`;
95 expect(str).to.be.equal(outCfg);
96 });
97
98 it('can serialize SystemJS configuration', () => {
99 let cfg = readConfig([inpCfg]);
100 let outCfg =
101 `SystemJS.config({
102 defaultJSExtensions: true
103});`;
104 let str = serializeConfig(cfg, true);
105 expect(str).to.be.equal(outCfg);
106 });
107
108 it('can detect System and/or SystemJS', () => {
109 let inpCfg = 'System.config({ defaultJSExtensions: true })';
110 let inpCfg2 = 'SystemJS.config({ valueFrom2ndFile : true })';
111 expect(isSystem(inpCfg)).to.be.true;
112 expect(isSystemJS(inpCfg2)).to.be.true;
113 });
114
115 it('does not quote top-level keys', () => {
116 let cfg = {
117 defaultJSExtensions: true,
118 baseURL: '',
119 bundles: {
120 'app-bundle.js': [
121 'app/boot',
122 'app/main'
123 ]
124 },
125 depCache: {
126 a: 'b',
127 c: 'd'
128 },
129 map: {}
130 };
131
132 let out =
133 `System.config({
134 defaultJSExtensions: true,
135 baseURL: "",
136 bundles: {
137 "app-bundle.js": [
138 "app/boot",
139 "app/main"
140 ]
141 },
142 depCache: {
143 "a": "b",
144 "c": "d"
145 },
146 map: {}
147});`;
148
149 let str = serializeConfig(cfg);
150 expect(str).to.be.equal(out);
151 });
152});