webpack/test/RecordIdsPlugin.test.js

47 lines
1.1 KiB
JavaScript
Raw Permalink Normal View History

2017-04-03 19:13:29 +08:00
/* globals describe, before, it */
2017-01-18 22:30:57 +08:00
"use strict";
2016-10-05 00:25:37 +08:00
2017-01-18 22:30:57 +08:00
const should = require("should");
const path = require("path");
const webpack = require("../lib/webpack");
const identifierUtils = require("../lib/util/identifier");
2016-10-05 00:25:37 +08:00
2017-01-18 22:30:57 +08:00
describe("RecordIdsPlugin", () => {
2016-10-05 00:25:37 +08:00
2017-01-18 22:30:57 +08:00
let compiler;
2016-10-05 00:25:37 +08:00
2017-01-18 22:30:57 +08:00
before(() => {
2016-10-05 00:25:37 +08:00
compiler = webpack({
entry: "./nodetest/entry",
context: path.join(__dirname, "fixtures"),
output: {
path: path.join(__dirname, "nodetest", "js"),
filename: "result1.js"
}
});
2017-01-18 22:30:57 +08:00
compiler.plugin("compilation", (compilation, callback) => {
compilation.plugin("should-record", () => true);
2016-10-05 00:25:37 +08:00
});
});
2017-01-18 22:30:57 +08:00
it("should cache identifiers", (done) => {
compiler.compile((err, compilation) => {
2016-10-05 00:25:37 +08:00
if(err) done(err);
2017-01-18 22:30:57 +08:00
let pass = true;
for(let i = 0; i < compilation.modules.length; i++) {
2016-10-05 00:25:37 +08:00
try {
should.exist(compilation.modules[i].portableId);
compilation.modules[i].portableId.should.equal(identifierUtils.makePathsRelative(compiler.context, compilation.modules[i].identifier()));
2016-10-05 00:25:37 +08:00
} catch(e) {
done(e);
pass = false;
break;
}
}
if(pass) done();
});
});
});