1 | import _ from 'lodash';
|
2 | import path from 'path';
|
3 | import webpack from 'webpack';
|
4 | import rimraf from 'rimraf';
|
5 | import fs from 'fs';
|
6 | import config from './webpack.config';
|
7 | import touch from 'touch';
|
8 | import AssetMapPlugin from '../src';
|
9 | import asyncTestWrapper from './async-test-wrapper';
|
10 |
|
11 | config = _.cloneDeep(config);
|
12 |
|
13 | var baseDir = path.join(__dirname, 'app');
|
14 |
|
15 | config.plugins = [
|
16 | new AssetMapPlugin(baseDir + '/assets/map.json')
|
17 | ];
|
18 |
|
19 | config.devtool = 'sourcemap';
|
20 |
|
21 | var mapFilePath = config.plugins[0].outputFile;
|
22 |
|
23 | describe('With source maps enabled', () => {
|
24 | it('Generates map.json with map to asset entries', done => {
|
25 | rimraf(config.output.path, () => {
|
26 | webpack(config, (err, stats) => {
|
27 | asyncTestWrapper(() => {
|
28 | if (err) throw err;
|
29 | if (stats.hasErrors()) throw 'webpack has errors';
|
30 | if (stats.hasWarnings()) throw 'webpack has warnings';
|
31 |
|
32 | var mapSrc = fs.readFileSync(mapFilePath, {encoding: 'utf-8'});
|
33 | var map = JSON.parse(mapSrc).assets;
|
34 |
|
35 | map['../smiley.jpeg'].should.match(/\/smiley-[0-9a-f]+\.jpeg$/);
|
36 | map['../test-checklist.jpeg'].should.match(/\/test-checklist-[0-9a-f]+\.jpeg$/);
|
37 | }, done);
|
38 | });
|
39 | });
|
40 | });
|
41 |
|
42 | it('Generates map.json with map to chunk entries, without map files', done => {
|
43 | rimraf(config.output.path, () => {
|
44 | webpack(config, (err, stats) => {
|
45 | asyncTestWrapper(() => {
|
46 | if (err) throw err;
|
47 | if (stats.hasErrors()) throw 'webpack has errors';
|
48 | if (stats.hasWarnings()) throw 'webpack has warnings';
|
49 |
|
50 | var mapSrc = fs.readFileSync(mapFilePath, {encoding: 'utf-8'});
|
51 | var map = JSON.parse(mapSrc).chunks;
|
52 |
|
53 | expect(map.entry1.length).to.equal(1);
|
54 | map.entry1[0].should.match(/^\/assets\/entry1-[0-9a-f]+\.js$/);
|
55 | expect(map.entry2.length).to.equal(1);
|
56 | map.entry2[0].should.match(/^\/assets\/entry2-[0-9a-f]+\.js$/);
|
57 | }, done);
|
58 | });
|
59 | })
|
60 | });
|
61 | });
|