UNPKG

2.46 kBJavaScriptView Raw
1/* eslint-env node, mocha */
2/* eslint-disable prefer-arrow-callback, func-names */
3
4// Dependencies.
5const assert = require('assert');
6const lib = require('./lib');
7const logger = require('../lib/logger');
8
9describe('FEBS Production Tests', function () {
10 let compile;
11
12 logger.setLogLevel('warn'); // Suppress info messages
13
14 beforeEach(function () {
15 process.env.FEBS_TEST = true;
16
17 compile = lib.createCompileFn(lib.createFS(), 'production');
18 });
19
20 it('js is minified', async function () {
21 const compiled = await compile(lib.createConf({
22 entry: {
23 app1: lib.absPath('fixtures/src/main-es2015.js'),
24 },
25 }));
26
27 assert(lib.compiledContains(compiled, {
28 entryName: /^app1$/,
29 content: /add:function/,
30 fileName: /\.js$/,
31 }));
32 });
33
34 it('js contains sourcemap', async function () {
35 const compiled = await compile(lib.createConf({
36 entry: {
37 app1: lib.absPath('fixtures/src/main-es2015.js'),
38 },
39 }));
40
41 // source and sourcemap.
42 assert.equal(compiled.code.app1.length, 2); // js and map
43
44 // sourcemap
45 assert(lib.compiledContains(compiled, {
46 entryName: /^app1$/,
47 fileName: /\.map/,
48 }));
49
50 assert(compiled.code.app1[0].content.length > 0);
51 });
52
53 it('versions js entry points', async function () {
54 const compiled = await compile(lib.createConf({
55 entry: {
56 app1: lib.absPath('fixtures/src/main-es2015.js'),
57 },
58 }));
59
60 assert(lib.compiledContains(compiled, {
61 entryName: /^app1$/,
62 fileName: /-[a-z0-9]{10,}\.js$/,
63 }));
64 });
65
66 it('versions css entry point', async function () {
67 const compiled = await compile(lib.createConf({
68 entry: {
69 app1: lib.absPath('fixtures/src/styles/main.less'),
70 },
71 }));
72
73 assert(lib.compiledContains(compiled, {
74 entryName: /^app1$/,
75 fileName: /-[a-z0-9]{10,}\.css$/,
76 }));
77 });
78
79 it('should return exit code 1 on syntax errors', async function () {
80 await compile(lib.createConf({
81 entry: {
82 app1: lib.absPath('fixtures/src/main-es2015-syntax-errors.js'),
83 },
84 })).then((o) => {
85 assert.equal(o.exitCode, 1);
86 });
87 });
88
89 it('should not return exit code 1 only lint errors', async function () {
90 await compile(lib.createConf({
91 entry: {
92 app1: lib.absPath('fixtures/src/main-es2015-lint-errors.js'),
93 },
94 })).then((o) => {
95 assert.equal(o.exitCode, 0);
96 });
97 });
98});