tkeron 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/CICD.yml +43 -0
- package/LICENSE +21 -0
- package/README.md +76 -0
- package/assets/tkexample.gif +0 -0
- package/changelog.md +8 -0
- package/dist/base64.d.ts +2 -0
- package/dist/base64.js +7 -0
- package/dist/build.d.ts +10 -0
- package/dist/build.js +102 -0
- package/dist/buildFront.d.ts +10 -0
- package/dist/buildFront.js +27 -0
- package/dist/buildLoaders.d.ts +13 -0
- package/dist/buildLoaders.js +23 -0
- package/dist/bundleTs.d.ts +1 -0
- package/dist/bundleTs.js +35 -0
- package/dist/cicd.d.ts +1 -0
- package/dist/cicd.js +8 -0
- package/dist/cmdBuild.d.ts +1 -0
- package/dist/cmdBuild.js +11 -0
- package/dist/cmdDev.d.ts +7 -0
- package/dist/cmdDev.js +63 -0
- package/dist/cmdGenerate.d.ts +1 -0
- package/dist/cmdGenerate.js +41 -0
- package/dist/cmdInit.d.ts +1 -0
- package/dist/cmdInit.js +36 -0
- package/dist/copyDir.d.ts +1 -0
- package/dist/copyDir.js +18 -0
- package/dist/createModFile.d.ts +1 -0
- package/dist/createModFile.js +14 -0
- package/dist/createTsConfigFile.d.ts +1 -0
- package/dist/createTsConfigFile.js +39 -0
- package/dist/eventEmitter.d.ts +5 -0
- package/dist/eventEmitter.js +29 -0
- package/dist/fileExist.d.ts +1 -0
- package/dist/fileExist.js +6 -0
- package/dist/generateItems.d.ts +11 -0
- package/dist/generateItems.js +16 -0
- package/dist/getDocument.d.ts +11 -0
- package/dist/getDocument.js +37 -0
- package/dist/getFilesRecursive.d.ts +9 -0
- package/dist/getFilesRecursive.js +53 -0
- package/dist/getOptions.d.ts +8 -0
- package/dist/getOptions.js +28 -0
- package/dist/getType.d.ts +1 -0
- package/dist/getType.js +5 -0
- package/dist/getVersion.d.ts +2 -0
- package/dist/getVersion.js +16 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/injectCode.d.ts +1 -0
- package/dist/injectCode.js +7 -0
- package/dist/injectTsFile.d.ts +8 -0
- package/dist/injectTsFile.js +22 -0
- package/dist/jsDom/crypto.d.ts +3 -0
- package/dist/jsDom/crypto.js +22 -0
- package/dist/jsDom/errors.d.ts +3 -0
- package/dist/jsDom/errors.js +30 -0
- package/dist/jsDom/joinScripts.d.ts +1 -0
- package/dist/jsDom/joinScripts.js +25 -0
- package/dist/jsDom/logs.d.ts +1 -0
- package/dist/jsDom/logs.js +10 -0
- package/dist/jsDom/writeLogElement.d.ts +1 -0
- package/dist/jsDom/writeLogElement.js +49 -0
- package/dist/libFiles.ts.d.ts +1 -0
- package/dist/libFiles.ts.js +14 -0
- package/dist/main.d.ts +1 -0
- package/dist/main.js +58 -0
- package/dist/mod.d.ts +3 -0
- package/dist/mod.js +9 -0
- package/dist/pathToUrlResource.d.ts +4 -0
- package/dist/pathToUrlResource.js +11 -0
- package/dist/random.d.ts +3 -0
- package/dist/random.js +31 -0
- package/dist/range.d.ts +1 -0
- package/dist/range.js +5 -0
- package/dist/readJsonFile.d.ts +1 -0
- package/dist/readJsonFile.js +20 -0
- package/dist/rectReady.d.ts +1 -0
- package/dist/rectReady.js +33 -0
- package/dist/rnd.d.ts +2 -0
- package/dist/rnd.js +11 -0
- package/dist/rnda.d.ts +1 -0
- package/dist/rnda.js +8 -0
- package/dist/runOncePerTime.d.ts +1 -0
- package/dist/runOncePerTime.js +17 -0
- package/dist/serializeDocument.d.ts +1 -0
- package/dist/serializeDocument.js +5 -0
- package/dist/simpleHotRestart.d.ts +1 -0
- package/dist/simpleHotRestart.js +17 -0
- package/dist/test/buildLoaders.test.d.ts +1 -0
- package/dist/test/buildLoaders.test.js +27 -0
- package/dist/test/bundleTs.test.d.ts +1 -0
- package/dist/test/bundleTs.test.js +94 -0
- package/dist/test/errors.test.d.ts +1 -0
- package/dist/test/errors.test.js +29 -0
- package/dist/test/fileExist.test.d.ts +1 -0
- package/dist/test/fileExist.test.js +26 -0
- package/dist/test/getFilesRecursive.test.d.ts +1 -0
- package/dist/test/getFilesRecursive.test.js +66 -0
- package/dist/test/getRandomValues.test.d.ts +1 -0
- package/dist/test/getRandomValues.test.js +35 -0
- package/dist/test/logs.test.d.ts +1 -0
- package/dist/test/logs.test.js +20 -0
- package/dist/test/main.test.d.ts +1 -0
- package/dist/test/main.test.js +15 -0
- package/dist/test/pathToUrlResource.test.d.ts +1 -0
- package/dist/test/pathToUrlResource.test.js +14 -0
- package/dist/test/runOncePerTime.test.d.ts +1 -0
- package/dist/test/runOncePerTime.test.js +17 -0
- package/dist/tk.d.ts +2 -0
- package/dist/tk.js +5 -0
- package/dist/tkeron.d.ts +44 -0
- package/dist/tkeron.js +258 -0
- package/dist/wait.d.ts +1 -0
- package/dist/wait.js +5 -0
- package/distFiles/eventEmitter.ts +29 -0
- package/distFiles/getType.ts +2 -0
- package/distFiles/random.ts +26 -0
- package/distFiles/range.ts +2 -0
- package/distFiles/rectReady.ts +27 -0
- package/distFiles/rnda.ts +5 -0
- package/distFiles/runOncePerTime.ts +12 -0
- package/distFiles/simpleHotRestart.ts +18 -0
- package/distFiles/tkeron.ts +317 -0
- package/package.json +47 -0
- package/src/base64.ts +3 -0
- package/src/build.ts +112 -0
- package/src/buildFront.ts +40 -0
- package/src/buildLoaders.ts +23 -0
- package/src/bundleTs.ts +32 -0
- package/src/cicd.ts +8 -0
- package/src/cmdBuild.ts +9 -0
- package/src/cmdDev.ts +68 -0
- package/src/cmdGenerate.ts +41 -0
- package/src/cmdInit.ts +37 -0
- package/src/copyDir.ts +16 -0
- package/src/createModFile.ts +15 -0
- package/src/createTsConfigFile.ts +37 -0
- package/src/eventEmitter.ts +29 -0
- package/src/fileExist.ts +4 -0
- package/src/generateItems.ts +16 -0
- package/src/getDocument.ts +40 -0
- package/src/getFilesRecursive.ts +49 -0
- package/src/getOptions.ts +27 -0
- package/src/getType.ts +2 -0
- package/src/getVersion.ts +14 -0
- package/src/index.ts +5 -0
- package/src/injectCode.ts +9 -0
- package/src/injectTsFile.ts +28 -0
- package/src/jsDom/crypto.ts +22 -0
- package/src/jsDom/errors.ts +35 -0
- package/src/jsDom/joinScripts.ts +22 -0
- package/src/jsDom/logs.ts +7 -0
- package/src/jsDom/writeLogElement.ts +45 -0
- package/src/libFiles.ts.ts +16 -0
- package/src/main.ts +67 -0
- package/src/mod.ts +7 -0
- package/src/pathToUrlResource.ts +10 -0
- package/src/random.ts +26 -0
- package/src/range.ts +2 -0
- package/src/readJsonFile.ts +16 -0
- package/src/rectReady.ts +27 -0
- package/src/rnd.ts +5 -0
- package/src/rnda.ts +5 -0
- package/src/runOncePerTime.ts +12 -0
- package/src/serializeDocument.ts +7 -0
- package/src/simpleHotRestart.ts +18 -0
- package/src/test/buildLoaders.test.ts +31 -0
- package/src/test/bundleTs.test.ts +98 -0
- package/src/test/errors.test.ts +31 -0
- package/src/test/fileExist.test.ts +29 -0
- package/src/test/getFilesRecursive.test.ts +67 -0
- package/src/test/getRandomValues.test.ts +34 -0
- package/src/test/logs.test.ts +20 -0
- package/src/test/main.test.ts +16 -0
- package/src/test/pathToUrlResource.test.ts +18 -0
- package/src/test/runOncePerTime.test.ts +16 -0
- package/src/tk.ts +5 -0
- package/src/tkeron.ts +317 -0
- package/src/wait.ts +2 -0
- package/tkeron.json +4 -0
- package/tkeron.tsconfig.json +12 -0
- package/tsconfig.json +29 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import fs from "fs";
|
|
2
|
+
import { normalize } from "path";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export const readJsonFile = (filePath: string) => {
|
|
6
|
+
try {
|
|
7
|
+
filePath = normalize(filePath);
|
|
8
|
+
const pkg = fs.readFileSync(filePath, { encoding: "utf-8" });
|
|
9
|
+
const json = JSON.parse(pkg);
|
|
10
|
+
return json;
|
|
11
|
+
} catch (_) {
|
|
12
|
+
return undefined;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
|
package/src/rectReady.ts
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
|
|
2
|
+
export const rectReady = async (querySelector: string, limit = 0): Promise<DOMRect> => {
|
|
3
|
+
const tryTimeout = 100;
|
|
4
|
+
let timeoutHandler = null;
|
|
5
|
+
let limitHandler = null;
|
|
6
|
+
return new Promise((ok, err) => {
|
|
7
|
+
const tryRect = () => {
|
|
8
|
+
const element = document.querySelector(querySelector);
|
|
9
|
+
if (!element) {
|
|
10
|
+
timeoutHandler = setTimeout(() => tryRect(), tryTimeout);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
const rect = element.getClientRects();
|
|
14
|
+
if (!rect || rect.length === 0) {
|
|
15
|
+
timeoutHandler = setTimeout(() => tryRect(), tryTimeout);
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
if (limitHandler) clearTimeout(limitHandler);
|
|
19
|
+
ok(rect[0]);
|
|
20
|
+
};
|
|
21
|
+
if (limit > 0) limitHandler = setTimeout(() => {
|
|
22
|
+
if (timeoutHandler) clearTimeout(timeoutHandler);
|
|
23
|
+
err("timeout");
|
|
24
|
+
}, limit);
|
|
25
|
+
tryRect();
|
|
26
|
+
});
|
|
27
|
+
};
|
package/src/rnd.ts
ADDED
package/src/rnda.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
|
|
2
|
+
export const runOncePerTime = (msec: number): (fn: any) => void => {
|
|
3
|
+
let lastDiff = 0;
|
|
4
|
+
let lastFunc = () => { };
|
|
5
|
+
return (fn: any) => {
|
|
6
|
+
lastFunc = fn;
|
|
7
|
+
const now = new Date().getTime();
|
|
8
|
+
if (now - lastDiff < msec) { return; }
|
|
9
|
+
lastFunc();
|
|
10
|
+
lastDiff = now;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
|
|
2
|
+
(async () => {
|
|
3
|
+
const review = async () => {
|
|
4
|
+
const cb = new Date().getTime();
|
|
5
|
+
const result = await fetch("/compdate.txt?cb=" + cb).then(_ => _.json())
|
|
6
|
+
.catch(_ => ({ reload: false }));
|
|
7
|
+
const { reload } = result as { reload: boolean };
|
|
8
|
+
if (reload) {
|
|
9
|
+
location.reload();
|
|
10
|
+
setTimeout(review, 618);
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
setTimeout(review, 618 * 2);
|
|
14
|
+
};
|
|
15
|
+
review();
|
|
16
|
+
})();
|
|
17
|
+
|
|
18
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildLoaders, getExtModules } from "../buildLoaders";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe("buildLoaders", () => {
|
|
7
|
+
it("verify loaders", () => {
|
|
8
|
+
const expectedKeys = ['.jpg', '.png', '.gif', '.ico', '.webp', '.svg', '.js', '.css', '.html'];
|
|
9
|
+
const expectedValues = ['file', 'file', 'file', 'file', 'file', 'file', 'file', 'text', 'text'];
|
|
10
|
+
const keys = Object.keys(buildLoaders);
|
|
11
|
+
const values = Object.values(buildLoaders);
|
|
12
|
+
expect(keys).toMatchObject(expectedKeys);
|
|
13
|
+
expect(values).toMatchObject(expectedValues);
|
|
14
|
+
});
|
|
15
|
+
it("verify ext modules", () => {
|
|
16
|
+
const expected = `declare module '*.css';
|
|
17
|
+
declare module '*.gif';
|
|
18
|
+
declare module '*.html';
|
|
19
|
+
declare module '*.ico';
|
|
20
|
+
declare module '*.jpg';
|
|
21
|
+
declare module '*.js';
|
|
22
|
+
declare module '*.png';
|
|
23
|
+
declare module '*.svg';
|
|
24
|
+
declare module '*.webp';
|
|
25
|
+
`.replace(/[\n\t]/g, " ").replace(/\s+/g, " ");
|
|
26
|
+
const extModules = getExtModules().replace(/[\n\t]/g, " ").replace(/\s+/g, " ");
|
|
27
|
+
expect(extModules).toBe(expected);
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { mkdir, writeFile, rm, readFile } from "fs/promises";
|
|
2
|
+
import { join } from "path";
|
|
3
|
+
import { bundleTs } from "../bundleTs";
|
|
4
|
+
import { fileExists } from "../fileExist";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const testDir = join(process.cwd(), "tmp_bundle_ts");
|
|
8
|
+
const sumDir = join(testDir, "sum.ts");
|
|
9
|
+
const minDir = join(testDir, "min.ts");
|
|
10
|
+
const powDir = join(testDir, "pow.ts");
|
|
11
|
+
const operationsDir = join(testDir, "operations.ts");
|
|
12
|
+
const sumOutDir = join(testDir, "sum.js");
|
|
13
|
+
const minOutDir = join(testDir, "min.js");
|
|
14
|
+
const powOutDir = join(testDir, "pow.js");
|
|
15
|
+
const operationsOutDir = join(testDir, "operations.js");
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
beforeAll(async () => {
|
|
19
|
+
if (await fileExists(testDir)) await rm(testDir, { recursive: true, force: true });
|
|
20
|
+
await mkdir(testDir);
|
|
21
|
+
const sum = `
|
|
22
|
+
//sum.ts
|
|
23
|
+
export const sum = (a: number, b: number) => a + b;
|
|
24
|
+
`;
|
|
25
|
+
const min = `
|
|
26
|
+
//min.ts
|
|
27
|
+
export const min = (a: number, b: number) => a - b;
|
|
28
|
+
`;
|
|
29
|
+
const pow = `
|
|
30
|
+
//pow.ts
|
|
31
|
+
export const pow = (a: number, b: number) => a ** b;
|
|
32
|
+
`;
|
|
33
|
+
const operations = `
|
|
34
|
+
//operations.ts
|
|
35
|
+
import {sum} from "./sum";
|
|
36
|
+
import {min} from "./min";
|
|
37
|
+
import {pow} from "./pow";
|
|
38
|
+
|
|
39
|
+
const a = 56;
|
|
40
|
+
const b = 12;
|
|
41
|
+
|
|
42
|
+
const sumResult = sum(a, b);
|
|
43
|
+
// const minResult = min(a, b);
|
|
44
|
+
const powResult = pow(a, b);
|
|
45
|
+
|
|
46
|
+
console\.log(\`a + b = $\{sumResult\}\`);
|
|
47
|
+
// console\.log(\`a - b = $\{minResult\}\`);
|
|
48
|
+
console\.log(\`a ** b = $\{powResult\}\`);
|
|
49
|
+
`;
|
|
50
|
+
writeFile(sumDir, sum, { encoding: "utf-8" });
|
|
51
|
+
writeFile(minDir, min, { encoding: "utf-8" });
|
|
52
|
+
writeFile(powDir, pow, { encoding: "utf-8" });
|
|
53
|
+
writeFile(operationsDir, operations, { encoding: "utf-8" });
|
|
54
|
+
});
|
|
55
|
+
afterAll(async () => {
|
|
56
|
+
await rm(testDir, { recursive: true, force: true });
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
describe("bundleTs", () => {
|
|
61
|
+
it("bundle with undefined file", async () => {
|
|
62
|
+
const result = await bundleTs(undefined, sumOutDir)
|
|
63
|
+
.catch(_ => _);
|
|
64
|
+
expect(result).toBe("file must be defined");
|
|
65
|
+
});
|
|
66
|
+
it("bundle with undefined out file", async () => {
|
|
67
|
+
const result = await bundleTs(sumDir, undefined)
|
|
68
|
+
.catch(_ => _);
|
|
69
|
+
expect(result).toBe("outfile must be defined");
|
|
70
|
+
});
|
|
71
|
+
it("bundle with unexistent file", async () => {
|
|
72
|
+
const file = join(testDir, "unexistent.ts");
|
|
73
|
+
const result = await bundleTs(file, sumOutDir)
|
|
74
|
+
.catch(_ => _);
|
|
75
|
+
expect(result).toBe(`file ${file} doesn't exist`);
|
|
76
|
+
});
|
|
77
|
+
it("bundle sum function", async () => {
|
|
78
|
+
const result = await bundleTs(sumDir, sumOutDir);
|
|
79
|
+
const expected = "(()=>{var sum=(a,b)=>a+b;})();";
|
|
80
|
+
expect(result.trim()).toBe(expected);
|
|
81
|
+
});
|
|
82
|
+
it("bundle min function", async () => {
|
|
83
|
+
const result = await bundleTs(minDir, minOutDir);
|
|
84
|
+
const expected = "(()=>{var min=(a,b)=>a-b;})();";
|
|
85
|
+
expect(result.trim()).toBe(expected);
|
|
86
|
+
});
|
|
87
|
+
it("bundle pow function", async () => {
|
|
88
|
+
const result = await bundleTs(powDir, powOutDir);
|
|
89
|
+
const expected = "(()=>{var pow=(a,b)=>a**b;})();";
|
|
90
|
+
expect(result.trim()).toBe(expected);
|
|
91
|
+
});
|
|
92
|
+
it("bundle operations, expecting tree shaking", async () => {
|
|
93
|
+
const result = await bundleTs(operationsDir, operationsOutDir);
|
|
94
|
+
const expected = "(()=>{var sum=(a2,b2)=>a2+b2;var pow=(a2,b2)=>a2**b2;var a=56,b=12,sumResult=sum(a,b),powResult=pow(a,b);console.log(`a + b = ${sumResult}`);console.log(`a ** b = ${powResult}`);})();";
|
|
95
|
+
expect(result.trim()).toBe(expected);
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { getDocument } from "../getDocument";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
const front = join(__dirname, "..", "..", "front");
|
|
6
|
+
const web = join(__dirname, "..", "..", "web");
|
|
7
|
+
|
|
8
|
+
describe("jsdom errors", () => {
|
|
9
|
+
it("custom error", async () => {
|
|
10
|
+
const html = `
|
|
11
|
+
<!DOCTYPE html>
|
|
12
|
+
<html lang="en">
|
|
13
|
+
<head>
|
|
14
|
+
<meta charset="UTF-8" />
|
|
15
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
16
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
17
|
+
<title>jsdom errors</title>
|
|
18
|
+
<script>
|
|
19
|
+
throw "custom error";
|
|
20
|
+
</script>
|
|
21
|
+
</head>
|
|
22
|
+
<body></body>
|
|
23
|
+
</html>
|
|
24
|
+
`;
|
|
25
|
+
const { document } = getDocument(html);
|
|
26
|
+
const node = document.querySelector(".tkeron_error");
|
|
27
|
+
expect(node).toBeTruthy();
|
|
28
|
+
expect(node.innerHTML).toMatch(/custom error/);
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { fileExists } from "../fileExist";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe("file exist", () => {
|
|
7
|
+
it("existent file", async () => {
|
|
8
|
+
const path = join(__dirname, "..", "tkeron.js");
|
|
9
|
+
const result = await fileExists(path);
|
|
10
|
+
expect(result).toBeTruthy();
|
|
11
|
+
});
|
|
12
|
+
it("unexistent file", async () => {
|
|
13
|
+
const path = join(__dirname, "..", "qwerty.asdf");
|
|
14
|
+
const result = await fileExists(path);
|
|
15
|
+
expect(result).toBeFalsy();
|
|
16
|
+
});
|
|
17
|
+
it("existent directory", async () => {
|
|
18
|
+
const path = join(__dirname, "..");
|
|
19
|
+
const result = await fileExists(path);
|
|
20
|
+
expect(result).toBeTruthy();
|
|
21
|
+
});
|
|
22
|
+
it("unexistent directory", async () => {
|
|
23
|
+
const path = join(__dirname, "..", "qwerty");
|
|
24
|
+
const result = await fileExists(path);
|
|
25
|
+
expect(result).toBeFalsy();
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import { mkdir, rm, writeFile } from "fs/promises";
|
|
2
|
+
import { join, dirname } from "path";
|
|
3
|
+
import { fileExists } from "../fileExist";
|
|
4
|
+
import { getFilesRecursive } from "../getFilesRecursive";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
const testDir = join(__dirname, "..", "..", "tmp_test_dir");
|
|
8
|
+
const filesPaths = [
|
|
9
|
+
join(testDir, "index.html"),
|
|
10
|
+
join(testDir, "style.css"),
|
|
11
|
+
join(testDir, "main.js"),
|
|
12
|
+
join(testDir, "robots.txt"),
|
|
13
|
+
join(testDir, "docs/index.html"),
|
|
14
|
+
join(testDir, "docs/main.js"),
|
|
15
|
+
join(testDir, "docs/style.css"),
|
|
16
|
+
join(testDir, "docs/robots.txt"),
|
|
17
|
+
join(testDir, "admin/index.html"),
|
|
18
|
+
join(testDir, "admin/main.js"),
|
|
19
|
+
join(testDir, "admin/style.css"),
|
|
20
|
+
join(testDir, "admin/robots.txt"),
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
beforeAll(async () => {
|
|
25
|
+
if (await fileExists(testDir)) await rm(testDir, { recursive: true, force: true });
|
|
26
|
+
await mkdir(testDir);
|
|
27
|
+
for (const path of filesPaths) {
|
|
28
|
+
const dir = dirname(path);
|
|
29
|
+
if (!await fileExists(dir)) mkdir(dir);
|
|
30
|
+
await writeFile(path, "...", { encoding: "utf-8" });
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
afterAll(async () => {
|
|
34
|
+
await rm(testDir, { recursive: true, force: true });
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
describe("getFilesRecursive", () => {
|
|
38
|
+
it("get all files", async () => {
|
|
39
|
+
const result = [...getFilesRecursive(testDir, { returnNamesOnly: true })];
|
|
40
|
+
expect(result).toMatchObject([
|
|
41
|
+
'style.css', 'robots.txt',
|
|
42
|
+
'main.js', 'index.html',
|
|
43
|
+
'style.css', 'robots.txt',
|
|
44
|
+
'main.js', 'index.html',
|
|
45
|
+
'style.css', 'robots.txt',
|
|
46
|
+
'main.js', 'index.html'
|
|
47
|
+
]);
|
|
48
|
+
});
|
|
49
|
+
it("get all files excluding some", async () => {
|
|
50
|
+
const result = [...getFilesRecursive(testDir, { returnNamesOnly: true, excludePattern: /\.html$/ })];
|
|
51
|
+
expect(result).toMatchObject([
|
|
52
|
+
'style.css', 'robots.txt',
|
|
53
|
+
'main.js', 'style.css',
|
|
54
|
+
'robots.txt', 'main.js',
|
|
55
|
+
'style.css', 'robots.txt',
|
|
56
|
+
'main.js'
|
|
57
|
+
]);
|
|
58
|
+
});
|
|
59
|
+
it("get all files with pattern", async () => {
|
|
60
|
+
const result = [...getFilesRecursive(testDir, { returnNamesOnly: true, pattern: /\.txt$/ })];
|
|
61
|
+
expect(result).toMatchObject(['robots.txt', 'robots.txt', 'robots.txt']);
|
|
62
|
+
});
|
|
63
|
+
it("get all files with pattern excluding some", async () => {
|
|
64
|
+
const result = [...getFilesRecursive(testDir, { returnNamesOnly: true, pattern: /\.txt$/, excludePattern: /\.html$/ })];
|
|
65
|
+
expect(result).toMatchObject(['robots.txt', 'robots.txt', 'robots.txt']);
|
|
66
|
+
});
|
|
67
|
+
});
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { getRandomValues } from "../jsDom/crypto";
|
|
2
|
+
|
|
3
|
+
describe("getRandomValues", () => {
|
|
4
|
+
it("random Int8Array", () => {
|
|
5
|
+
const result = getRandomValues(new Int8Array(5));
|
|
6
|
+
expect(result).toBeTruthy();
|
|
7
|
+
expect(result).toHaveLength(5);
|
|
8
|
+
});
|
|
9
|
+
it("random Uint8Array", () => {
|
|
10
|
+
const result = getRandomValues(new Uint8Array(5));
|
|
11
|
+
expect(result).toBeTruthy();
|
|
12
|
+
expect(result).toHaveLength(5);
|
|
13
|
+
});
|
|
14
|
+
it("random Int16Array", () => {
|
|
15
|
+
const result = getRandomValues(new Int16Array(5));
|
|
16
|
+
expect(result).toBeTruthy();
|
|
17
|
+
expect(result).toHaveLength(5);
|
|
18
|
+
});
|
|
19
|
+
it("random Uint16Array", () => {
|
|
20
|
+
const result = getRandomValues(new Uint16Array(5));
|
|
21
|
+
expect(result).toBeTruthy();
|
|
22
|
+
expect(result).toHaveLength(5);
|
|
23
|
+
});
|
|
24
|
+
it("random Int32Array", () => {
|
|
25
|
+
const result = getRandomValues(new Int32Array(5));
|
|
26
|
+
expect(result).toBeTruthy();
|
|
27
|
+
expect(result).toHaveLength(5);
|
|
28
|
+
});
|
|
29
|
+
it("random Uint32Array", () => {
|
|
30
|
+
const result = getRandomValues(new Uint32Array(5));
|
|
31
|
+
expect(result).toBeTruthy();
|
|
32
|
+
expect(result).toHaveLength(5);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { JSDOM } from "jsdom";
|
|
2
|
+
import { pageItem } from "../generateItems";
|
|
3
|
+
import { handleLogs } from "../jsDom/logs";
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
describe("logs", () => {
|
|
7
|
+
it("handleLogs", async () => {
|
|
8
|
+
const logs = ["log 1", "log B", "log 3"];
|
|
9
|
+
const { window } = new JSDOM(pageItem("test").html, { runScripts: "dangerously", resources: "usable" });
|
|
10
|
+
const { document } = window;
|
|
11
|
+
await new Promise(ok => document.addEventListener("load", ok));
|
|
12
|
+
handleLogs(logs, document);
|
|
13
|
+
const logNodes = document.querySelectorAll(".tkeron_log");
|
|
14
|
+
expect(logNodes).toHaveLength(3);
|
|
15
|
+
const [log1, log2, log3] = logNodes;
|
|
16
|
+
expect(log1.innerHTML).toBe(logs[0]);
|
|
17
|
+
expect(log2.innerHTML).toBe(logs[1]);
|
|
18
|
+
expect(log3.innerHTML).toBe(logs[2]);
|
|
19
|
+
});
|
|
20
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { mkdir, rm, rmdir } from "fs/promises";
|
|
2
|
+
import { main } from "../main";
|
|
3
|
+
|
|
4
|
+
beforeAll(async () => {
|
|
5
|
+
await mkdir("front", { recursive: true });
|
|
6
|
+
});
|
|
7
|
+
afterAll(async () => {
|
|
8
|
+
await rm("front", { force: true, recursive: true });
|
|
9
|
+
});
|
|
10
|
+
|
|
11
|
+
describe("main", () => {
|
|
12
|
+
it("command build", () => {
|
|
13
|
+
main("tk", ["build"]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { join } from "path";
|
|
2
|
+
import { pathToUrlResource } from "../pathToUrlResource";
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
describe("pathToUrlResource", () => {
|
|
8
|
+
it("test dir from 1 level up", async () => {
|
|
9
|
+
const result = pathToUrlResource(__dirname, join(__dirname, ".."));
|
|
10
|
+
expect(result).toMatchObject({ url: '/test', resource: 'test' });
|
|
11
|
+
});
|
|
12
|
+
it("test dir from 2 levels up", async () => {
|
|
13
|
+
const result = pathToUrlResource(__dirname, join(__dirname, "..", ".."));
|
|
14
|
+
expect(result).toMatchObject({ url: '/dist/test', resource: 'dist__test' });
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { runOncePerTime } from "../runOncePerTime";
|
|
2
|
+
|
|
3
|
+
describe("runOncePerTime", () => {
|
|
4
|
+
it("run once in 20ms", (done) => {
|
|
5
|
+
const runOnce20ms = runOncePerTime(20);
|
|
6
|
+
const result: number[] = [];
|
|
7
|
+
const add = (n: number) => result.push(n);
|
|
8
|
+
setTimeout(() => {
|
|
9
|
+
expect(result).toHaveLength(1);
|
|
10
|
+
done();
|
|
11
|
+
}, 20);
|
|
12
|
+
setTimeout(() => runOnce20ms(() => add(1)), 5);
|
|
13
|
+
setTimeout(() => runOnce20ms(() => add(1)), 4);
|
|
14
|
+
setTimeout(() => runOnce20ms(() => add(1)), 3);
|
|
15
|
+
});
|
|
16
|
+
});
|