UNPKG

1.99 kBJavaScriptView Raw
1import _ from 'lodash';
2import path from 'path';
3import webpack from 'webpack';
4import rimraf from 'rimraf';
5import fs from 'fs';
6import config from './webpack.config';
7import touch from 'touch';
8import AssetMapPlugin from '../src';
9import asyncTestWrapper from './async-test-wrapper';
10
11config = _.cloneDeep(config);
12
13var baseDir = path.join(__dirname, 'app');
14
15config.plugins = [
16 new AssetMapPlugin(baseDir + '/assets/map.json')
17];
18
19config.devtool = 'sourcemap';
20
21var mapFilePath = config.plugins[0].outputFile;
22
23describe('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});