This repository was archived by the owner on Jul 3, 2025. It is now read-only.
forked from avajs/create-ava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
164 lines (133 loc) · 4.03 KB
/
test.js
File metadata and controls
164 lines (133 loc) · 4.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
const path = require("path");
const fs = require("fs");
const { it } = require("quyz");
const dotProp = require("dot-prop");
const execa = require("execa");
const tempWrite = require("temp-write");
const createPetzl = require(".");
const assert = require("assert");
const { get } = dotProp;
const runWithoutInstall = async (packageJson, additionalOptions) => {
const filePath = tempWrite.sync(
JSON.stringify(packageJson),
"package.json"
);
await createPetzl({
cwd: path.dirname(filePath),
skipInstall: true,
...additionalOptions,
});
return JSON.parse(fs.readFileSync(filePath, "utf8"));
};
it("empty package.json", async () => {
assert.strictEqual(
get(await runWithoutInstall({}), "scripts.test"),
"quyz"
);
});
it("has scripts", async () => {
const pkg = await runWithoutInstall({
scripts: {
start: "",
},
});
assert.strictEqual(get(pkg, "scripts.test"), "quyz");
});
it("has default test", async () => {
const pkg = await runWithoutInstall({
scripts: {
test: 'echo "Error: no test specified" && exit 1',
},
});
assert.strictEqual(get(pkg, "scripts.test"), "quyz");
});
it("has only quyz", async () => {
const pkg = await runWithoutInstall({
scripts: {
test: "quyz",
},
});
assert.strictEqual(get(pkg, "scripts.test"), "quyz");
});
it("has test", async () => {
const pkg = await runWithoutInstall({
scripts: {
test: "foo",
},
});
assert.strictEqual(get(pkg, "scripts.test"), "foo && quyz");
});
it("has cli args", async () => {
const args = ["--foo"];
const pkg = await runWithoutInstall(
{
scripts: {
start: "",
},
},
{ args }
);
assert.strictEqual(get(pkg, "scripts.test"), "quyz --foo");
});
it("has cli args and existing binary", async () => {
const args = ["--foo", "--bar"];
const pkg = await runWithoutInstall(
{
scripts: {
test: "foo",
},
},
{ args }
);
assert.strictEqual(get(pkg, "scripts.test"), "foo && quyz --foo --bar");
});
it("does not remove empty dependency properties", async () => {
const pkg = await runWithoutInstall({
dependencies: {},
devDependencies: {},
optionalDependencies: {},
peerDependencies: {},
});
assert(get(pkg, "dependencies"));
assert(get(pkg, "devDependencies"));
assert(get(pkg, "optionalDependencies"));
assert(get(pkg, "peerDependencies"));
});
it("installs the petzl dependency", async () => {
const filepath = tempWrite.sync(JSON.stringify({}), "package.json");
await createPetzl({ cwd: path.dirname(filepath) });
const installed = get(
JSON.parse(fs.readFileSync(filepath, "utf8")),
"devDependencies.petzl"
);
assert(installed);
assert.strictEqual(installed.match(/^\^/).length, 1);
});
it("installs via yarn if there's a lockfile", async () => {
const yarnLock = tempWrite.sync("", "yarn.lock");
await createPetzl({ cwd: path.dirname(yarnLock) });
assert.strictEqual(
fs.readFileSync(yarnLock, "utf8").match(/^\^/).length,
1
);
});
it("invokes via cli", async () => {
const cliFilepath = path.resolve(__dirname, "./cli.js");
const filepath = tempWrite.sync(JSON.stringify({}), "package.json");
await execa(cliFilepath, [], { cwd: path.dirname(filepath) });
assert.strictEqual(
get(JSON.parse(fs.readFileSync(filepath, "utf8")), "scripts.test"),
"petzl"
);
});
it("interprets cli arguments", async () => {
const cliFilepath = path.resolve(__dirname, "./cli.js");
const filepath = tempWrite.sync(JSON.stringify({}), "package.json");
await execa(cliFilepath, ["--foo", "--bar"], {
cwd: path.dirname(filepath),
});
assert.strictEqual(
get(JSON.parse(fs.readFileSync(filepath, "utf8")), "scripts.test"),
"petzl --foo --bar"
);
});