-
Notifications
You must be signed in to change notification settings - Fork 610
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
close #107
- Loading branch information
Showing
3 changed files
with
78 additions
and
38 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,78 @@ | ||
import { getEffectLoaders, isMatchUrl } from "../../src/plugin"; | ||
import defaultPlugin, { getEffectLoaders, isMatchUrl } from "../../src/plugin"; | ||
|
||
describe("utils test", () => { | ||
describe("getEffectLoaders", () => { | ||
test("plugins is undefined, should return empty array", () => { | ||
expect(getEffectLoaders("jsExcludes", [])).toEqual([]); | ||
expect(getEffectLoaders("cssExcludes", [])).toEqual([]); | ||
}); | ||
describe("test getEffectLoaders", () => { | ||
test("plugins is undefined, should return empty array", () => { | ||
expect(getEffectLoaders("jsExcludes", [])).toEqual([]); | ||
expect(getEffectLoaders("cssExcludes", [])).toEqual([]); | ||
}); | ||
|
||
test('sourceType is "jsExcludes", should return jsExcludes', () => { | ||
const jsExcludes = ["https://www.foo/a.js", /b\.js/]; | ||
const plugins = [ | ||
{ | ||
jsExcludes, | ||
}, | ||
]; | ||
expect(getEffectLoaders("jsExcludes", plugins)).toEqual(jsExcludes); | ||
}); | ||
|
||
test('sourceType is "jsExcludes", should return jsExcludes', () => { | ||
const jsExcludes = ["https://www.foo/a.js", /b\.js/]; | ||
const plugins = [ | ||
{ | ||
jsExcludes, | ||
}, | ||
]; | ||
expect(getEffectLoaders("jsExcludes", plugins)).toEqual(jsExcludes); | ||
}); | ||
test('sourceType is "cssExcludes", should return cssExcludes', () => { | ||
const cssExcludes = ["https://www.foo/a.css", /b\.css/]; | ||
const plugins = [ | ||
{ | ||
cssExcludes, | ||
}, | ||
]; | ||
expect(getEffectLoaders("cssExcludes", plugins)).toEqual(cssExcludes); | ||
}); | ||
}); | ||
|
||
describe("test isMatchUrl", () => { | ||
test("url is not exclude, should return false", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", ["https://www.foo/b.js"])).toBe(false); | ||
}); | ||
test("url is exclude, should return true", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", ["https://www.foo/a.js"])).toBe(true); | ||
}); | ||
test("url is match regexp, should return true", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", [/a\.js/])).toBe(true); | ||
}); | ||
}); | ||
|
||
test('sourceType is "cssExcludes", should return cssExcludes', () => { | ||
const cssExcludes = ["https://www.foo/a.css", /b\.css/]; | ||
const plugins = [ | ||
{ | ||
cssExcludes, | ||
}, | ||
]; | ||
expect(getEffectLoaders("cssExcludes", plugins)).toEqual(cssExcludes); | ||
}); | ||
}); | ||
describe("isMatchUrl", () => { | ||
test("url is not exclude, should return false", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", ["https://www.foo/b.js"])).toBe(false); | ||
}); | ||
test("url is exclude, should return true", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", ["https://www.foo/a.js"])).toBe(true); | ||
}); | ||
test("url is match regexp, should return true", () => { | ||
expect(isMatchUrl("https://www.foo/a.js", [/a\.js/])).toBe(true); | ||
}); | ||
describe("test default cssLoader plugin", () => { | ||
const cssLoader = defaultPlugin.cssLoader; | ||
test("test relative code with src", () => { | ||
const relativeCode = "background-image: url('./test.gif');"; | ||
const src = "https://test.com/base/home"; | ||
const resultCode = cssLoader(relativeCode, src, ""); | ||
expect(resultCode).toBe("background-image: url('https://test.com/base/test.gif');"); | ||
}); | ||
test("test relative code with base", () => { | ||
const relativeCode = "background-image: url('./test.gif');"; | ||
const base = "https://test.com/base/home"; | ||
const resultCode = cssLoader(relativeCode, "", base); | ||
expect(resultCode).toBe("background-image: url('https://test.com/base/test.gif');"); | ||
}); | ||
test("test relative code with src and base", () => { | ||
const relativeCode = "background-image: url('./test.gif');"; | ||
const url = "./home/"; | ||
const base = "https://test.com/base/"; | ||
const resultCode = cssLoader(relativeCode, url, base); | ||
expect(resultCode).toBe("background-image: url('https://test.com/base/home/test.gif');"); | ||
}); | ||
test("test relative code with src and base", () => { | ||
const relativeCode = "background-image: url(./test.gif);"; | ||
const url = "./home/"; | ||
const base = "https://test.com/base/"; | ||
const resultCode = cssLoader(relativeCode, url, base); | ||
expect(resultCode).toBe("background-image: url(https://test.com/base/home/test.gif);"); | ||
}); | ||
test("test base data code with src and base", () => { | ||
const relativeCode = | ||
"background-image: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAFIAAABSCAYAAADHLIObAAAAMUlEQVR4nO3BMQEAAADCoPVPbQ0PoAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA3gxpYgAB841K1AAAAABJRU5ErkJggg==);"; | ||
const url = "./home/"; | ||
const base = "https://test.com/base/"; | ||
const resultCode = cssLoader(relativeCode, url, base); | ||
expect(resultCode).toBe(relativeCode); | ||
}); | ||
}); |
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