-
Notifications
You must be signed in to change notification settings - Fork 300
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add unit test, fix lint errors and warnings for xarc/subapp (#1826)
- Loading branch information
Showing
23 changed files
with
608 additions
and
14 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,4 +1,10 @@ | ||
const { eslintRcNodeTypeScript } = require("@xarc/module-dev"); | ||
module.exports = { | ||
extends: eslintRcNodeTypeScript | ||
extends: eslintRcNodeTypeScript, | ||
plugins: ["jsdoc"], | ||
rules: { | ||
// disable the rule for all files | ||
"@typescript-eslint/explicit-module-boundary-types": "off", | ||
"jsdoc/require-param-type": "off" | ||
} | ||
}; |
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
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
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
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
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
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,72 @@ | ||
import "jsdom-global/register"; | ||
import { | ||
declareSubApp, | ||
getContainer, | ||
_setupEnvHooks, | ||
IS_BROWSER | ||
} from "../../../src/browser/index"; | ||
import { envHooks } from "../../../src/subapp/index"; | ||
import { describe, it } from "mocha"; | ||
import { expect } from "chai"; | ||
|
||
describe("browser index", () => { | ||
afterEach(() => { | ||
(window as any)._subapps = undefined; | ||
}); | ||
|
||
describe("getContainer", () => { | ||
it("should getContainer create a new subapp container at first time", () => { | ||
const container = getContainer(); | ||
expect(container).is.an("object"); | ||
|
||
const container2 = getContainer(); | ||
expect(container).equal(container2); | ||
}); | ||
}); | ||
|
||
describe("_setupEnvHooks", () => { | ||
it("should _setupEnvHooks set getContainer to envHooks", () => { | ||
_setupEnvHooks(); | ||
expect(envHooks.getContainer).equal(getContainer); | ||
|
||
const getCon = envHooks.getContainer; | ||
_setupEnvHooks(); | ||
expect(envHooks.getContainer).equal(getCon); | ||
}); | ||
}); | ||
|
||
describe("declareSubApp", () => { | ||
it("should add the subapp into container", async () => { | ||
const container = getContainer(); | ||
|
||
const subapp = declareSubApp({ | ||
name: "test", | ||
getModule: () => import("../../blah") | ||
}); | ||
expect(container.getNames()).contains("test"); | ||
expect(container.get("test")).to.equal(subapp); | ||
expect(subapp._module).to.equal(undefined); | ||
|
||
const mod = await subapp._getModule(); | ||
|
||
expect(subapp._module).to.equal(mod); | ||
expect(mod.subapp.Component()).to.equal("hello"); // eslint-disable-line | ||
}); | ||
}); | ||
|
||
describe("IS_BROWSER", () => { | ||
it("should IS_BROWSER be true", () => { | ||
expect(IS_BROWSER).true; // eslint-disable-line | ||
}); | ||
}); | ||
|
||
it("serverOverrideMethods exist", () => { | ||
getContainer(); | ||
const subapp = declareSubApp({ | ||
name: "test", | ||
getModule: () => import("../../blah") | ||
}); | ||
|
||
expect(subapp._start).to.be.a("function"); | ||
}); | ||
}); |
31 changes: 31 additions & 0 deletions
31
packages/xarc-subapp/test/spec/browser/webpack4-jsonp.spec.ts
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,31 @@ | ||
import { webpack4JsonP } from "../../../src/browser/webpack4-jsonp"; | ||
import { describe, it } from "mocha"; | ||
import { expect } from "chai"; | ||
|
||
const mockWindow: any = {}; | ||
describe("webpack4JsonP", () => { | ||
it("should webpack4JsonP set __webpack_get_script_src__ method on window", () => { | ||
webpack4JsonP(mockWindow); | ||
expect(mockWindow.__webpack_get_script_src__).to.be.a("function"); | ||
}); | ||
|
||
it("should __webpack_get_script_src__ return original src when CDN is enabled", () => { | ||
mockWindow.xarcV2 = { | ||
cdnMap: src => "cdnMap" + src | ||
}; | ||
|
||
expect(mockWindow.__webpack_get_script_src__("chunkId", "publicPath", "/test/src")).equal( | ||
"cdnMap/test/src" | ||
); | ||
}); | ||
|
||
it("should __webpack_get_script_src__ return original src when CDN is disabled", () => { | ||
mockWindow.xarcV2 = { | ||
cdnMap: str => undefined // eslint-disable-line | ||
}; | ||
|
||
expect(mockWindow.__webpack_get_script_src__("chunkId", "publicPath", "/test/src")).equal( | ||
"/test/src" | ||
); | ||
}); | ||
}); |
28 changes: 28 additions & 0 deletions
28
packages/xarc-subapp/test/spec/browser/xarc-cdn-map.spec.ts
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,28 @@ | ||
import { xarcCdnMap } from "../../../src/browser/xarc-cdn-map"; | ||
import { xarcV2Client } from "../../../src/browser/xarc-subapp-v2"; | ||
|
||
import { describe, it } from "mocha"; | ||
import { expect } from "chai"; | ||
require("jsdom-global")("", { url: "https://localhost/" }); // eslint-disable-line | ||
|
||
const mockWindow = Object.assign({}, window); | ||
describe("xarcCdnMap", () => { | ||
it("should xarcCdnMap return undefined when window not having xarcV2 attribute", () => { | ||
expect(xarcCdnMap(mockWindow)).undefined; // eslint-disable-line | ||
}); | ||
|
||
it("should xarcCdnMap add subapp2 global attribute and method on window object", () => { | ||
xarcV2Client(mockWindow); | ||
xarcCdnMap(mockWindow); | ||
const xarcV2 = (mockWindow as any).xarcV2; | ||
expect(xarcV2).to.be.an("object"); | ||
expect(xarcV2.cdnInit).to.be.a("function"); | ||
expect(xarcV2.cdnUpdate).to.be.a("function"); | ||
expect(xarcV2.cdnMap).to.be.a("function"); | ||
expect((mockWindow as any)._wml.cdn.map).equal(xarcV2.cdnMap); | ||
expect((mockWindow as any)._wml.cdn.update).equal(xarcV2.cdnUpdate); | ||
expect((mockWindow as any)._wml.cdn.md) | ||
.equal(xarcV2.rt.md) | ||
.eql({}); | ||
}); | ||
}); |
Oops, something went wrong.