-
Notifications
You must be signed in to change notification settings - Fork 767
/
build.spec.ts
73 lines (56 loc) · 2.58 KB
/
build.spec.ts
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
import { expectFilesWritten } from '../../../testing/utils';
import { TestingCompiler } from '../../../testing/index';
describe('build', () => {
it('should minify es5 build', async () => {
c.config.bundles = [ { components: ['cmp-a'] } ];
c.config.minifyJs = true;
c.config.buildEs5 = true;
await c.fs.writeFile('/src/cmp-a.tsx', `@Component({ tag: 'cmp-a' }) export class CmpA { /** minify me plz **/ }`);
await c.fs.commit();
const r = await c.build();
expect(r.diagnostics).toEqual([]);
const output = await c.fs.readFile('/www/build/app/cmp-a.es5.js');
/*! Built with http://stenciljs.com */
expect(output).toContain('App.loadBundle(\"cmp-a\",[\"exports\"],function(e){window.App.h,window.App.Context;var n=function(){function e(){}return Object.defineProperty(e,\"is\",{get:function(){return\"cmp-a\"},enumerable:!0,configurable:!0}),e}();e.CmpA=n,Object.defineProperty(e,\"__esModule\",{value:!0})});');
});
it('should minify es2015 build', async () => {
c.config.bundles = [ { components: ['cmp-a'] } ];
c.config.minifyJs = true;
await c.fs.writeFile('/src/cmp-a.tsx', `@Component({ tag: 'cmp-a' }) export class CmpA { /** minify me plz **/ }`);
await c.fs.commit();
const r = await c.build();
expect(r.diagnostics).toEqual([]);
const output = await c.fs.readFile('/www/build/app/cmp-a.js');
expect(output).toContain('/*! Built with http://stenciljs.com */\nconst{h:t,Context:s}=window.App;class c{static get is(){return"cmp-a"}}export{c as CmpA};');
});
it('should build one component', async () => {
c.config.bundles = [ { components: ['cmp-a'] } ];
await c.fs.writeFile('/src/cmp-a.tsx', `@Component({ tag: 'cmp-a' }) export class CmpA {}`);
await c.fs.commit();
const r = await c.build();
expect(r.diagnostics).toEqual([]);
expect(r.entries).toHaveLength(1);
expect(r.entries[0].components[0].tag).toContain('cmp-a');
expect(r.transpileBuildCount).toBe(1);
expect(r.bundleBuildCount).toBe(1);
expectFilesWritten(r,
'/src/components.d.ts',
'/www/build/app/cmp-a.js',
'/www/index.html'
);
expect(r.filesWritten.length).toBe(3);
});
it('should build no components', async () => {
const r = await c.build();
expect(r.diagnostics).toEqual([]);
expect(r.entries).toHaveLength(0);
expect(r.transpileBuildCount).toBe(0);
expect(r.bundleBuildCount).toBe(0);
});
var c: TestingCompiler;
beforeEach(async () => {
c = new TestingCompiler();
await c.fs.writeFile('/src/index.html', `<cmp-a></cmp-a>`);
await c.fs.commit();
});
});