Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
232 changes: 110 additions & 122 deletions lib/__tests__/index__0.10.0__.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,43 @@ var EXPECTED_FILENAME_LIST = [
"package.json"
];
describe("UnusedFilesWebpackPlugin module", function() {
it(
"should work as expected",
function(done) {
it("should work as expected", function(done) {
var compiler = (0, _webpack.default)({
mode: "none",
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname // It will be in MemoryFS :)
},
plugins: [new _index.default()]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);

var _warnings = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings[0];

expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
var containsExpected = EXPECTED_FILENAME_LIST.every(function(filename) {
return message.match(filename);
});
expect(containsExpected).toBeTruthy();
done();
});
}, 10000);
describe("deprecated options.pattern", function() {
it("should work as expected", function(done) {
var compiler = (0, _webpack.default)({
mode: "none",
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
Expand All @@ -33,143 +66,98 @@ describe("UnusedFilesWebpackPlugin module", function() {
)
},
output: {
path: __dirname // It will be in MemoryFS :)
path: __dirname
},
plugins: [new _index.default()]
plugins: [
new _index.default({
pattern: "src/**/*.*"
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);

var _warnings = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings[0];
var _warnings2 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings2[0];

expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
var containsExpected = EXPECTED_FILENAME_LIST.every(function(filename) {
return message.match(filename);
});
expect(containsExpected).toBeTruthy();
expect(message).toMatchSnapshot();
done();
});
},
10000
);
describe("deprecated options.pattern", function() {
it(
"should work as expected",
function(done) {
var compiler = (0, _webpack.default)({
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname
},
plugins: [
new _index.default({
pattern: "src/**/*.*"
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);

var _warnings2 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings2[0];

expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
expect(message).toMatchSnapshot();
done();
});
},
10000
);
}, 10000);
});
describe("options.patterns", function() {
it(
"should work as expected for a single pattern",
function(done) {
var compiler = (0, _webpack.default)({
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname
},
plugins: [
new _index.default({
patterns: ["src/**/*.*"]
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);
it("should work as expected for a single pattern", function(done) {
var compiler = (0, _webpack.default)({
mode: "none",
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname
},
plugins: [
new _index.default({
patterns: ["src/**/*.*"]
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);

var _warnings3 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings3[0];
var _warnings3 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings3[0];

expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
expect(message).toMatchSnapshot();
done();
});
},
10000
);
it(
"should work as expected for an array of patterns",
function(done) {
var compiler = (0, _webpack.default)({
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname
},
plugins: [
new _index.default({
patterns: ["src/**/*.*", "!**/__snapshots__/**/*.*"]
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);
expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
expect(message).toMatchSnapshot();
done();
});
}, 10000);
it("should work as expected for an array of patterns", function(done) {
var compiler = (0, _webpack.default)({
mode: "none",
context: _path.default.resolve(__dirname, "../../"),
entry: {
UnusedFilesWebpackPlugin: _path.default.resolve(
__dirname,
"../index.js"
)
},
output: {
path: __dirname
},
plugins: [
new _index.default({
patterns: ["src/**/*.*", "!**/__snapshots__/**/*.*"]
})
]
});
compiler.outputFileSystem = new _memoryFs.default();
compiler.run(function(err, stats) {
expect(err).toBeFalsy();
var warnings = stats.compilation.warnings;
expect(warnings).toHaveLength(1);

var _warnings4 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings4[0];
var _warnings4 = (0, _slicedToArray2.default)(warnings, 1),
unusedFilesError = _warnings4[0];

expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
expect(message).toMatchSnapshot();
done();
});
},
10000
);
expect(unusedFilesError).toBeInstanceOf(Error);
var message = unusedFilesError.message;
expect(message).toMatchSnapshot();
done();
});
}, 10000);
});
});
Loading