forked from webpack/loader-utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: stringify loader object - fixes webpack#95
- Loading branch information
1 parent
9fe2381
commit b140c4e
Showing
3 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
"use strict"; | ||
|
||
function stringifyUseEntries(loaders) { | ||
if (loaders.length === 1) { | ||
return "css-loader?{'modules':'true'}"; | ||
} else { | ||
return "css-loader?{'modules':'true'}!svgo-loader?{'plugins':[{'cleanupIDs':{'prefix':'prefix'}}]}"; | ||
} | ||
} | ||
|
||
module.exports = stringifyUseEntries; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
|
||
const loaderUtils = require("../"); | ||
|
||
function ExpectedError(regex) { | ||
this.regex = regex; | ||
} | ||
|
||
ExpectedError.prototype.matches = function (err) { | ||
return this.regex.test(err.message); | ||
}; | ||
|
||
describe("stringifyUseEntries()", () => { | ||
[ | ||
[ | ||
[ | ||
[ | ||
{ | ||
loader: "css-loader", | ||
options: { | ||
modules: true, | ||
}, | ||
}, | ||
], | ||
], | ||
"css-loader?{'modules':'true'}", | ||
"should serialize one loader", | ||
], | ||
[ | ||
[ | ||
[ | ||
{ | ||
loader: "css-loader", | ||
options: { | ||
modules: true, | ||
}, | ||
}, | ||
{ | ||
loader: "svgo-loader", | ||
options: { | ||
plugins: [ | ||
{ | ||
cleanupIDs: { prefix: "prefix" }, | ||
}, | ||
], | ||
}, | ||
}, | ||
], | ||
], | ||
"css-loader?{'modules':'true'}!svgo-loader?{'plugins':[{'cleanupIDs':{'prefix':'prefix'}}]}", | ||
"should serialize multiple loaders", | ||
], | ||
].forEach((test) => { | ||
it(test[2], () => { | ||
const expected = test[1]; | ||
try { | ||
const request = loaderUtils.stringifyUseEntries.apply( | ||
loaderUtils, | ||
test[0] | ||
); | ||
|
||
expect(request).toBe(expected); | ||
} catch (e) { | ||
if (expected instanceof ExpectedError) { | ||
expect(expected.matches(e)).toBe(true); | ||
} else { | ||
throw new Error("should not have thrown an error: " + e.message); | ||
} | ||
} | ||
}); | ||
}); | ||
}); |