Skip to content

Commit 790a66e

Browse files
committed
build: added more tests
1 parent b8aab7b commit 790a66e

File tree

6 files changed

+151
-1
lines changed

6 files changed

+151
-1
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"compile:ci": "pnpm run build:ts",
2121
"build:ts": "pnpm run build:ts:cjs",
2222
"build:ts:cjs": "tsc -p src",
23-
"test": "cross-env TS_NODE_PROJECT='./tests/tsconfig.json' nyc mocha",
23+
"test": "cross-env TS_NODE_PROJECT='./tests/tsconfig.json' nyc mocha --timeout 300000",
2424
"build": "pnpm run clear:dist && pnpm run prettify:src && pnpm run lint && pnpm run compile && pnpm run prettify:readme && chmod +x dist/cli.js && chmod +x dist/build/build.js && chmod +x dist/create/create.js && chmod +x dist/create/preset/preset.js",
2525
"build:ci": "pnpm run clear:dist && pnpm run prettify:ci:src && pnpm run lint:ci && pnpm run compile && pnpm run prettify:ci:readme",
2626
"clear:dist": "rimraf ./dist",

tests/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
tmp-files

tests/create-plugin.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, it } from "mocha";
2+
import { expect } from "chai";
3+
import { createPluginTemplate } from "../src/create/plugin/create-plugin";
4+
import path from "path";
5+
import fs from "fs-extra";
6+
7+
describe("create-plugin", async () => {
8+
it("should have created the plugin project", async () => {
9+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "foo-plugin"));
10+
11+
await createPluginTemplate("foo", "Foo", "", destDir);
12+
13+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
14+
15+
expect(pkgInfo.name).to.be.equal("tsparticles-plugin-foo");
16+
17+
await fs.remove(destDir);
18+
});
19+
20+
it("should have created the plugin project, w/ repo", async () => {
21+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "bar-plugin"));
22+
23+
await createPluginTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
24+
25+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
26+
27+
expect(pkgInfo.name).to.be.equal("tsparticles-plugin-bar");
28+
29+
await fs.remove(destDir);
30+
});
31+
});

tests/create-preset.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, it } from "mocha";
2+
import { expect } from "chai";
3+
import { createPresetTemplate } from "../src/create/preset/create-preset";
4+
import path from "path";
5+
import fs from "fs-extra";
6+
7+
describe("create-plugin", async () => {
8+
it("should have created the preset project", async () => {
9+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "foo-preset"));
10+
11+
await createPresetTemplate("foo", "Foo", "", destDir);
12+
13+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
14+
15+
expect(pkgInfo.name).to.be.equal("tsparticles-preset-foo");
16+
17+
await fs.remove(destDir);
18+
});
19+
20+
it("should have created the preset project, w/ repo", async () => {
21+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "bar-preset"));
22+
23+
await createPresetTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
24+
25+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
26+
27+
expect(pkgInfo.name).to.be.equal("tsparticles-preset-bar");
28+
29+
await fs.remove(destDir);
30+
});
31+
});

tests/create-shape.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { describe, it } from "mocha";
2+
import { expect } from "chai";
3+
import { createShapeTemplate } from "../src/create/shape/create-shape";
4+
import path from "path";
5+
import fs from "fs-extra";
6+
7+
describe("create-shape", async () => {
8+
it("should have created the shape project", async () => {
9+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "foo-shape"));
10+
11+
await createShapeTemplate("foo", "Foo", "", destDir);
12+
13+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
14+
15+
expect(pkgInfo.name).to.be.equal("tsparticles-shape-foo");
16+
17+
await fs.remove(destDir);
18+
});
19+
20+
it("should have created the shape project, w/ repo", async () => {
21+
const destDir = path.resolve(path.join(__dirname, "tests", "tmp-files", "bar-shape"));
22+
23+
await createShapeTemplate("bar", "Bar", "https://github.com/matteobruni/tsparticles", destDir);
24+
25+
const pkgInfo = await fs.readJSON(path.join(destDir, "package.json"));
26+
27+
expect(pkgInfo.name).to.be.equal("tsparticles-shape-bar");
28+
29+
await fs.remove(destDir);
30+
});
31+
});

tests/file-utils.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { describe, it } from "mocha";
2+
import { expect } from "chai";
3+
import fs from "fs-extra";
4+
import path from "path";
5+
import { replaceTokensInFile, replaceTokensInFiles } from "../src/utils/file-utils";
6+
7+
describe("file-utils", async () => {
8+
const baseDir = path.join(__dirname, "tests", "tmp-files");
9+
10+
await fs.ensureDir(baseDir);
11+
12+
describe("replace tokens in files", async () => {
13+
fs.writeFileSync(path.join(baseDir, "files1.txt"), "test");
14+
fs.writeFileSync(path.join(baseDir, "files2.txt"), "test");
15+
16+
await replaceTokensInFiles([{
17+
path: path.join(baseDir, "files1.txt"),
18+
tokens: [{
19+
from: "test",
20+
to: "test1",
21+
}],
22+
}, {
23+
path: path.join(baseDir, "files2.txt"),
24+
tokens: [{
25+
from: "test",
26+
to: "test2",
27+
}],
28+
}]);
29+
30+
it("should replace tokens in files", async () => {
31+
const data1 = await fs.readFile(path.join(baseDir, "files1.txt"), "utf8"),
32+
data2 = await fs.readFile(path.join(baseDir, "files2.txt"), "utf8");
33+
34+
expect(data1).to.be.equal("test1");
35+
expect(data2).to.be.equal("test2");
36+
});
37+
});
38+
39+
describe("replace tokens in file", async () => {
40+
fs.writeFileSync(path.join(baseDir, "file1.txt"), "test");
41+
42+
await replaceTokensInFile({
43+
path: path.join(baseDir, "file1.txt"),
44+
tokens: [{
45+
from: "test",
46+
to: "test1",
47+
}],
48+
});
49+
50+
it("should replace tokens in files", async () => {
51+
const data = await fs.readFile(path.join(baseDir, "file1.txt"), "utf8");
52+
53+
expect(data).to.be.equal("test1");
54+
});
55+
});
56+
});

0 commit comments

Comments
 (0)