Skip to content

Commit

Permalink
Vitestに移行(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
ienaga committed Nov 5, 2023
1 parent 75b840f commit 4df5387
Show file tree
Hide file tree
Showing 8 changed files with 373 additions and 5 deletions.
80 changes: 80 additions & 0 deletions src/domain/callback/Callback.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import { execute } from "./Callback";
import { packages } from "../../application/variable/Packages";

describe("CallbackTest", () =>
{
test("execute test case1", () =>
{
execute()
.then((result) =>
{
expect(result).toBe(undefined);
});
});

test("execute single test", () =>
{
// mock
const SingleTest = class SingleTest
{
execute (value: any): any
{
return value;
}
};

packages.clear();
packages.set("SingleTest", SingleTest);

execute("SingleTest", "single test")
.then((results: string[] | void) =>
{
if (!results) {
throw new Error("stop test");
}

expect(results.length).toBe(1);
const result: string = results[0];
expect(result).toBe("single test");
});
});

test("execute multiple test", () =>
{
// mock
const MultipleTestCase1 = class MultipleTest
{
execute (value: any): any
{
return `${value}_1`;
}
};

const MultipleTestCase2 = class MultipleTest
{
execute (value: any): any
{
return `${value}_2`;
}
};

packages.clear();
packages.set("multiple.test.case1", MultipleTestCase1);
packages.set("multiple.test.case2", MultipleTestCase2);

execute(["multiple.test.case1", "multiple.test.case2"], "multiple test")
.then((results: string[] | void) =>
{
if (!results) {
throw new Error("stop test");
}

expect(results.length).toBe(2);
const result1: string = results[0];
expect(result1).toBe("multiple test_1");

const result2: string = results[1];
expect(result2).toBe("multiple test_2");
});
});
});
19 changes: 19 additions & 0 deletions src/domain/convert/ToCamelCase.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { execute } from "./ToCamelCase";

describe("ToCamelCaseTest", () =>
{
test("execute test case1", () =>
{
expect(execute("home")).toBe("Home");
});

test("execute test case2", () =>
{
expect(execute("quest/list")).toBe("QuestList");
});

test("execute test case3", () =>
{
expect(execute("game/list/page")).toBe("GameListPage");
});
});
251 changes: 251 additions & 0 deletions src/domain/parser/QueryParser.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,251 @@
import { execute } from "./QueryParser";
import { query } from "../../application/variable/Query";
import { $setConfig } from "../../application/variable/Config";
import { QueryObjectImpl } from "../../interface/QueryObjectImpl";
import { vi } from "vitest";

Object.defineProperty(window, "location", {
"get": vi.fn().mockReturnValue({
"search": "",
"pathname": ""
})
});

describe("QueryParserTest", () =>
{
test("parse query test case1", () =>
{
query.clear();
query.set("test", 123);
expect(query.size).toBe(1);

const object: QueryObjectImpl = execute();

expect(query.size).toBe(0);
expect(object.name).toBe("top");
expect(object.queryString).toBe("");
});

test("parse query test case2", () =>
{
query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("@test");

expect(query.size).toBe(0);
expect(object.name).toBe("test");
expect(object.queryString).toBe("");
});

test("parse location.search test case1", () =>
{
// @ts-ignore
globalThis.location.search = "?q=abc&sample=1";

query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("");

expect(query.size).toBe(2);
expect(query.get("q")).toBe("abc");
expect(query.get("sample")).toBe("1");
expect(object.name).toBe("top");
expect(object.queryString).toBe("?q=abc&sample=1");
});

test("parse location.pathname un match test", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"top": {}
}
};

$setConfig(config);

// @ts-ignore
globalThis.location.pathname = "/quest/list";

// @ts-ignore
globalThis.location.search = "?q=xyz&sample=0";

query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("");

expect(query.size).toBe(2);
expect(query.get("q")).toBe("xyz");
expect(query.get("sample")).toBe("0");
expect(object.name).toBe("top");
expect(object.queryString).toBe("?q=xyz&sample=0");
});

test("parse location.pathname public test", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"quest/list": {
"private": false
}
}
};

$setConfig(config);

// @ts-ignore
globalThis.location.pathname = "/quest/list";

// @ts-ignore
globalThis.location.search = "?q=xyz&sample=0";

query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("");

expect(query.size).toBe(2);
expect(query.get("q")).toBe("xyz");
expect(query.get("sample")).toBe("0");
expect(object.name).toBe("quest/list");
expect(object.queryString).toBe("?q=xyz&sample=0");
});

test("parse location.pathname private test", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"quest/list": {
"private": true
}
}
};

$setConfig(config);

// @ts-ignore
globalThis.location.pathname = "/quest/list";

// @ts-ignore
globalThis.location.search = "?q=xyz&sample=0";

query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("");

expect(query.size).toBe(2);
expect(query.get("q")).toBe("xyz");
expect(query.get("sample")).toBe("0");
expect(object.name).toBe("top");
expect(object.queryString).toBe("?q=xyz&sample=0");
});

test("parse location.pathname redirect test", () =>
{
// mock
const config = {
"platform": "web",
"spa": true,
"stage": {
"width": 240,
"height": 240,
"fps": 12,
"options": {}
},
"routing": {
"quest/list": {
"private": true,
"redirect": "quest/detail"
}
}
};

$setConfig(config);

// @ts-ignore
globalThis.location.pathname = "/quest/list";

// @ts-ignore
globalThis.location.search = "?q=xyz&sample=0";

query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("");

expect(query.size).toBe(2);
expect(query.get("q")).toBe("xyz");
expect(query.get("sample")).toBe("0");
expect(object.name).toBe("quest/detail");
expect(object.queryString).toBe("?q=xyz&sample=0");
});

test("parse name query test", () =>
{
// mock
query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("page/test?abc=123&xyz=999");

expect(query.size).toBe(2);
expect(query.get("abc")).toBe("123");
expect(query.get("xyz")).toBe("999");
expect(object.name).toBe("page/test");
expect(object.queryString).toBe("?abc=123&xyz=999");
});

test("parse name path test case1", () =>
{
// mock
query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("./test");

expect(query.size).toBe(0);
expect(object.name).toBe("test");
});

test("parse name path test case2", () =>
{
// mock
query.clear();
expect(query.size).toBe(0);

const object: QueryObjectImpl = execute("./");

expect(query.size).toBe(0);
expect(object.name).toBe("top");
});
});
2 changes: 0 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import "@next2d/player";
import { Application } from "./application/Application";
import { DefaultLoading } from "./domain/screen/DefaultLoading";
import { View } from "./view/View";
import { ViewModel } from "./view/ViewModel";
import { MovieClipContent } from "./application/content/MovieClipContent";
Expand All @@ -24,7 +23,6 @@ console.log("%c Next2D Framework %c 2.0.0 %c https://next2d.app",
const app: Application = new Application();
export {
app,
DefaultLoading,
View,
ViewModel,
MovieClipContent,
Expand Down
18 changes: 18 additions & 0 deletions src/infrastructure/dto/ResponseDTO.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { ResponseDTO } from "./ResponseDTO";

describe("ResponseDTOTest", () =>
{
test("execute test case1", () =>
{
const responseDTO = new ResponseDTO();
expect(responseDTO.name).toBe("");
expect(responseDTO.response).toBe(null);
});

test("execute test case2", () =>
{
const responseDTO = new ResponseDTO("sample", 100);
expect(responseDTO.name).toBe("sample");
expect(responseDTO.response).toBe(100);
});
});
Loading

0 comments on commit 4df5387

Please sign in to comment.