add test
This commit is contained in:
parent
964fb971dd
commit
4faa5c7203
|
@ -149,7 +149,7 @@ class ContextModule extends Module {
|
|||
this.resolveDependencies = undefined;
|
||||
}
|
||||
|
||||
prettyRegExp(regexString, stripSlash = true) {
|
||||
_prettyRegExp(regexString, stripSlash = true) {
|
||||
const str = (regexString + "").replace(/!/g, "%21").replace(/\|/g, "%7C");
|
||||
return stripSlash ? str.substring(1, str.length - 1) : str;
|
||||
}
|
||||
|
@ -172,16 +172,16 @@ class ContextModule extends Module {
|
|||
identifier += `|${this.options.addon}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += `|${this.prettyRegExp(this.options.regExp, false)}`;
|
||||
identifier += `|${this._prettyRegExp(this.options.regExp, false)}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += `|include: ${this.prettyRegExp(
|
||||
identifier += `|include: ${this._prettyRegExp(
|
||||
this.options.include,
|
||||
false
|
||||
)}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += `|exclude: ${this.prettyRegExp(
|
||||
identifier += `|exclude: ${this._prettyRegExp(
|
||||
this.options.exclude,
|
||||
false
|
||||
)}`;
|
||||
|
@ -234,13 +234,13 @@ class ContextModule extends Module {
|
|||
identifier += ` ${requestShortener.shorten(this.options.addon)}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += ` ${this.prettyRegExp(this.options.regExp)}`;
|
||||
identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += ` include: ${this.prettyRegExp(this.options.include)}`;
|
||||
identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`;
|
||||
identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
|
||||
}
|
||||
if (this.options.referencedExports) {
|
||||
identifier += ` referencedExports: ${this.options.referencedExports
|
||||
|
@ -289,13 +289,13 @@ class ContextModule extends Module {
|
|||
)}`;
|
||||
}
|
||||
if (this.options.regExp) {
|
||||
identifier += ` ${this.prettyRegExp(this.options.regExp)}`;
|
||||
identifier += ` ${this._prettyRegExp(this.options.regExp)}`;
|
||||
}
|
||||
if (this.options.include) {
|
||||
identifier += ` include: ${this.prettyRegExp(this.options.include)}`;
|
||||
identifier += ` include: ${this._prettyRegExp(this.options.include)}`;
|
||||
}
|
||||
if (this.options.exclude) {
|
||||
identifier += ` exclude: ${this.prettyRegExp(this.options.exclude)}`;
|
||||
identifier += ` exclude: ${this._prettyRegExp(this.options.exclude)}`;
|
||||
}
|
||||
if (this.options.referencedExports) {
|
||||
identifier += ` referencedExports: ${this.options.referencedExports
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
"use strict";
|
||||
|
||||
const ContextModule = require("../lib/ContextModule");
|
||||
|
||||
describe("contextModule", () => {
|
||||
let contextModule;
|
||||
let request;
|
||||
beforeEach(() => {
|
||||
request = "/some/request";
|
||||
});
|
||||
describe("#identifier", () => {
|
||||
it("returns an safe identifier for this module", () => {
|
||||
contextModule = new ContextModule(() => {}, {
|
||||
type: "javascript/auto",
|
||||
request,
|
||||
mode: "lazy",
|
||||
regExp: /a|b/
|
||||
});
|
||||
expect(contextModule.identifier()).toContain("/a%7Cb/");
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue