eleventy-test 0.1.2 → 1.0.0
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/README.md +7 -5
- package/dist/ScenarioOutput.d.ts +1 -1
- package/dist/eleventyUtils.d.ts +1 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +142 -69
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -24,13 +24,15 @@ Want to see how it is in action? For the dogfooding fans, you can see this libra
|
|
|
24
24
|
import { buildScenarios } from "eleventy-test";
|
|
25
25
|
import test from "ava";
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const resultsAsDict = await buildScenarios({
|
|
28
|
+
projectRoot: cwd(),
|
|
29
|
+
returnArray: false
|
|
30
|
+
});
|
|
29
31
|
|
|
30
|
-
test("Check if index.html is consistent across builds", t => {
|
|
32
|
+
test("Check if index.html is consistent across builds", async t => {
|
|
31
33
|
t.deepEqual(
|
|
32
|
-
results["3--example"].getFileContent("/index.html"),
|
|
33
|
-
results["3.0.0--identical-example"].getFileContent("/index.html"));
|
|
34
|
+
await results["3--example"].getFileContent("/index.html"),
|
|
35
|
+
await results["3.0.0--identical-example"].getFileContent("/index.html"));
|
|
34
36
|
});
|
|
35
37
|
```
|
|
36
38
|
|
package/dist/ScenarioOutput.d.ts
CHANGED
package/dist/eleventyUtils.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import ScenarioOutput from "./ScenarioOutput";
|
|
2
|
-
export declare function ensureEleventyExists(projectRoot: string, eleventyVersion: string): string
|
|
2
|
+
export declare function ensureEleventyExists(projectRoot: string, eleventyVersion: string): Promise<string>;
|
|
3
3
|
export declare function buildEleventy({ eleventyVersion, scenarioDir, scenarioName, projectRoot, globalInputDir }: {
|
|
4
4
|
eleventyVersion: any;
|
|
5
5
|
scenarioDir: any;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,18 @@
|
|
|
1
1
|
import ScenarioOutput from "./ScenarioOutput";
|
|
2
2
|
export * from "./eleventyUtils";
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
interface IbuildScenariosArgs {
|
|
4
|
+
projectRoot: string;
|
|
5
|
+
returnArray?: boolean;
|
|
6
|
+
scenariosDir?: string;
|
|
7
|
+
globalInputDir?: string;
|
|
8
|
+
}
|
|
9
|
+
interface IbuildScenariosArrayArgs extends IbuildScenariosArgs {
|
|
10
|
+
returnArray?: true;
|
|
11
|
+
}
|
|
12
|
+
interface IbuildScenariosDictArgs extends IbuildScenariosArgs {
|
|
13
|
+
returnArray?: false;
|
|
14
|
+
}
|
|
15
|
+
export declare function buildScenarios(opts: IbuildScenariosArrayArgs): Promise<ScenarioOutput[]>;
|
|
16
|
+
export declare function buildScenarios(opts: IbuildScenariosDictArgs): Promise<{
|
|
5
17
|
[key: string]: ScenarioOutput;
|
|
6
18
|
}>;
|
package/dist/index.js
CHANGED
|
@@ -26,11 +26,13 @@ __export(src_exports, {
|
|
|
26
26
|
module.exports = __toCommonJS(src_exports);
|
|
27
27
|
var import_process2 = require("process");
|
|
28
28
|
var import_path3 = require("path");
|
|
29
|
-
var
|
|
29
|
+
var import_promises2 = require("fs/promises");
|
|
30
|
+
var import_https = require("https");
|
|
30
31
|
|
|
31
32
|
// src/eleventyUtils.ts
|
|
32
33
|
var import_child_process = require("child_process");
|
|
33
34
|
var import_fs2 = require("fs");
|
|
35
|
+
var import_promises = require("fs/promises");
|
|
34
36
|
var import_path2 = require("path");
|
|
35
37
|
var import_process = require("process");
|
|
36
38
|
|
|
@@ -73,37 +75,58 @@ var ScenarioOutput = class {
|
|
|
73
75
|
return this._files;
|
|
74
76
|
}
|
|
75
77
|
getFileContent(filename) {
|
|
76
|
-
|
|
77
|
-
this.cache
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
return new Promise(async (resolve, reject) => {
|
|
79
|
+
if (!Object.keys(this.cache).includes(filename)) {
|
|
80
|
+
this.cache[filename] = this._files[filename]();
|
|
81
|
+
}
|
|
82
|
+
resolve(this.cache[filename]);
|
|
83
|
+
});
|
|
80
84
|
}
|
|
81
85
|
};
|
|
82
86
|
|
|
83
87
|
// src/eleventyUtils.ts
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
(0,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const eleventyDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/eleventy" + eleventyVersion);
|
|
94
|
-
if ((0, import_fs2.existsSync)(eleventyDir)) {
|
|
95
|
-
return eleventyDir;
|
|
96
|
-
} else {
|
|
97
|
-
console.log(`Eleventy version ${eleventyVersion} could not be found. Installing...`);
|
|
98
|
-
if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, "package-lock.json"))) {
|
|
99
|
-
installEleventy(eleventyVersion, projectRoot, "npm install --save-dev");
|
|
100
|
-
} else if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, "yarn.lock"))) {
|
|
101
|
-
installEleventy(eleventyVersion, projectRoot, "yarn add -D");
|
|
88
|
+
async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, filename, command) {
|
|
89
|
+
return new Promise(async (resolve, reject) => {
|
|
90
|
+
if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, filename))) {
|
|
91
|
+
try {
|
|
92
|
+
(0, import_child_process.execSync)(`${command} @11ty/eleventy${eleventyVersion}@npm:@11ty/eleventy@${eleventyVersion}`, { cwd: projectRoot });
|
|
93
|
+
resolve(true);
|
|
94
|
+
} catch (e) {
|
|
95
|
+
throw e;
|
|
96
|
+
}
|
|
102
97
|
} else {
|
|
103
|
-
|
|
98
|
+
console.error(`Couldn't detect ${filename}, skipping ${command.split(" ")[0]}...`);
|
|
99
|
+
resolve(false);
|
|
104
100
|
}
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
async function ensureEleventyExists(projectRoot, eleventyVersion) {
|
|
104
|
+
return new Promise(async (resolve, reject) => {
|
|
105
|
+
const eleventyDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/eleventy" + eleventyVersion);
|
|
106
|
+
try {
|
|
107
|
+
await (0, import_promises.access)(eleventyDir);
|
|
108
|
+
resolve(eleventyDir);
|
|
109
|
+
} catch {
|
|
110
|
+
console.log(`Eleventy version ${eleventyVersion} could not be found. Installing...`);
|
|
111
|
+
if (await installEleventyIfPkgManagerFound(
|
|
112
|
+
eleventyVersion,
|
|
113
|
+
projectRoot,
|
|
114
|
+
"package-lock.json",
|
|
115
|
+
"npm install --save-dev"
|
|
116
|
+
)) {
|
|
117
|
+
resolve(eleventyDir);
|
|
118
|
+
} else if (await installEleventyIfPkgManagerFound(
|
|
119
|
+
eleventyVersion,
|
|
120
|
+
projectRoot,
|
|
121
|
+
"yarn.lock",
|
|
122
|
+
"yarn add -D"
|
|
123
|
+
)) {
|
|
124
|
+
resolve(eleventyDir);
|
|
125
|
+
} else {
|
|
126
|
+
throw new Error(`Error while installing eleventy${eleventyVersion}: Could not determine package manager`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
});
|
|
107
130
|
}
|
|
108
131
|
async function buildEleventy({
|
|
109
132
|
eleventyVersion,
|
|
@@ -112,22 +135,32 @@ async function buildEleventy({
|
|
|
112
135
|
projectRoot = (0, import_process.cwd)(),
|
|
113
136
|
globalInputDir
|
|
114
137
|
}) {
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const eleventyDir = ensureEleventyExists(projectRoot, eleventyVersion);
|
|
138
|
+
return new Promise(async (resolve, reject) => {
|
|
139
|
+
const eleventyDir = await ensureEleventyExists(projectRoot, eleventyVersion);
|
|
117
140
|
const bin = JSON.parse(
|
|
118
|
-
(0,
|
|
141
|
+
await (0, import_promises.readFile)(
|
|
119
142
|
(0, import_path2.join)(eleventyDir, "package.json"),
|
|
120
143
|
{ encoding: "utf-8" }
|
|
121
144
|
)
|
|
122
145
|
).bin.eleventy;
|
|
123
146
|
const pathToBin = (0, import_path2.join)(eleventyDir, bin);
|
|
124
147
|
const scenarioInputDir = (0, import_path2.join)(scenarioDir, "input");
|
|
125
|
-
|
|
148
|
+
let inputDir;
|
|
149
|
+
try {
|
|
150
|
+
await (0, import_promises.access)(scenarioInputDir);
|
|
151
|
+
inputDir = scenarioInputDir;
|
|
152
|
+
} catch {
|
|
153
|
+
try {
|
|
154
|
+
await (0, import_promises.access)(globalInputDir);
|
|
155
|
+
inputDir = globalInputDir;
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
}
|
|
126
159
|
if (inputDir == void 0) {
|
|
127
160
|
throw Error("inputDir is undefined!");
|
|
128
161
|
}
|
|
129
162
|
const outputDir = (0, import_path2.join)(scenarioDir, "eleventy-test-out");
|
|
130
|
-
(0,
|
|
163
|
+
await (0, import_promises.rm)(outputDir, { force: true, recursive: true });
|
|
131
164
|
try {
|
|
132
165
|
const out = (0, import_child_process.fork)(
|
|
133
166
|
pathToBin,
|
|
@@ -137,9 +170,8 @@ async function buildEleventy({
|
|
|
137
170
|
out.on("message", (msg) => {
|
|
138
171
|
console.log(msg);
|
|
139
172
|
});
|
|
140
|
-
out.on("close", (code) => {
|
|
141
|
-
|
|
142
|
-
resolve(output);
|
|
173
|
+
out.on("close", async (code) => {
|
|
174
|
+
resolve(new ScenarioOutput(outputDir, scenarioName));
|
|
143
175
|
});
|
|
144
176
|
} catch (e) {
|
|
145
177
|
throw e;
|
|
@@ -148,48 +180,89 @@ async function buildEleventy({
|
|
|
148
180
|
}
|
|
149
181
|
|
|
150
182
|
// src/index.ts
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
for (let i2 = 0; i2 < versions.length; i2++) {
|
|
165
|
-
const version = versions[i2];
|
|
166
|
-
if (!version.name.includes("-") && version.name[1] == scenarioMajorVersion) {
|
|
167
|
-
scenarioEleventyVersion = version.name.substring(1);
|
|
168
|
-
break;
|
|
183
|
+
var versions;
|
|
184
|
+
async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
185
|
+
let eleventyVersion = scenarioDirname.includes("--") ? scenarioDirname.split("--")[0] : scenarioDirname;
|
|
186
|
+
if (eleventyVersion.length < 5) {
|
|
187
|
+
const scenarioMajorVersion = scenarioDirname[0];
|
|
188
|
+
if (versions == void 0) {
|
|
189
|
+
console.log("Pulling Eleventy tags...");
|
|
190
|
+
versions = await new Promise((resolve, reject) => {
|
|
191
|
+
(0, import_https.get)({
|
|
192
|
+
hostname: "api.github.com",
|
|
193
|
+
path: "/repos/11ty/eleventy/tags",
|
|
194
|
+
headers: {
|
|
195
|
+
"User-Agent": "Mozilla/5.0"
|
|
169
196
|
}
|
|
170
|
-
}
|
|
197
|
+
}, (res) => {
|
|
198
|
+
let data = [];
|
|
199
|
+
res.on("data", (chunk) => {
|
|
200
|
+
data.push(chunk);
|
|
201
|
+
}).on("end", () => {
|
|
202
|
+
console.log("Parsing API response...");
|
|
203
|
+
resolve(
|
|
204
|
+
JSON.parse(
|
|
205
|
+
Buffer.concat(data).toString("utf-8")
|
|
206
|
+
)
|
|
207
|
+
);
|
|
208
|
+
}).on("error", (err) => {
|
|
209
|
+
throw err;
|
|
210
|
+
});
|
|
211
|
+
});
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
for (let i = 0; i < versions.length; i++) {
|
|
215
|
+
const version = versions[i];
|
|
216
|
+
if (!version.name.includes("-") && version.name[1] == scenarioMajorVersion) {
|
|
217
|
+
eleventyVersion = version.name.substring(1);
|
|
218
|
+
break;
|
|
171
219
|
}
|
|
172
|
-
scenarioOutputs.push(await buildEleventy({
|
|
173
|
-
eleventyVersion: scenarioEleventyVersion,
|
|
174
|
-
scenarioName: scenarioDirname,
|
|
175
|
-
globalInputDir,
|
|
176
|
-
projectRoot,
|
|
177
|
-
scenarioDir
|
|
178
|
-
}));
|
|
179
220
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
221
|
+
}
|
|
222
|
+
return eleventyVersion;
|
|
223
|
+
}
|
|
224
|
+
async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), returnArray = true, scenariosDir = "tests/scenarios/", globalInputDir = "tests/input" }) {
|
|
225
|
+
return new Promise(async (resolve, reject) => {
|
|
226
|
+
scenariosDir = (0, import_path3.isAbsolute)(scenariosDir) ? scenariosDir : (0, import_path3.join)(projectRoot, scenariosDir);
|
|
227
|
+
globalInputDir = (0, import_path3.isAbsolute)(globalInputDir) ? globalInputDir : (0, import_path3.join)(projectRoot, globalInputDir);
|
|
228
|
+
try {
|
|
229
|
+
await (0, import_promises2.access)(globalInputDir);
|
|
230
|
+
} catch {
|
|
231
|
+
globalInputDir = "undefined";
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
const scenarioDirs = await (0, import_promises2.readdir)(scenariosDir, { recursive: false, encoding: "utf-8" });
|
|
235
|
+
const scenarioOutputs = [];
|
|
236
|
+
for (let i = 0; i < scenarioDirs.length; i++) {
|
|
237
|
+
const scenarioDirname = scenarioDirs[i];
|
|
238
|
+
const scenarioDir = (0, import_path3.join)(scenariosDir, scenarioDirname);
|
|
239
|
+
let scenarioEleventyVersion = await scenarioDirnameToEleventyVersion(scenarioDirname);
|
|
240
|
+
scenarioOutputs.push(await buildEleventy({
|
|
241
|
+
eleventyVersion: scenarioEleventyVersion,
|
|
242
|
+
scenarioName: scenarioDirname,
|
|
243
|
+
globalInputDir,
|
|
244
|
+
projectRoot,
|
|
245
|
+
scenarioDir
|
|
246
|
+
}));
|
|
247
|
+
}
|
|
248
|
+
if (returnArray) {
|
|
249
|
+
resolve(scenarioOutputs);
|
|
250
|
+
} else {
|
|
251
|
+
const returnDict = {};
|
|
252
|
+
scenarioOutputs.forEach((scenarioOutput) => {
|
|
253
|
+
returnDict[scenarioOutput.title] = scenarioOutput;
|
|
254
|
+
});
|
|
255
|
+
resolve(returnDict);
|
|
256
|
+
}
|
|
257
|
+
} catch (e) {
|
|
258
|
+
throw e;
|
|
188
259
|
}
|
|
189
260
|
});
|
|
190
261
|
}
|
|
191
262
|
if (require.main === module) {
|
|
192
|
-
buildScenarios(
|
|
263
|
+
buildScenarios({
|
|
264
|
+
projectRoot: (0, import_process2.cwd)()
|
|
265
|
+
});
|
|
193
266
|
}
|
|
194
267
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
268
|
0 && (module.exports = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-test",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Multi-configuration testing for Eleventy plugins",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/Denperidge/eleventy-test.git",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"build": "npm-run-all --serial build:js build:types",
|
|
16
16
|
"build:js": "esbuild src/index.ts --bundle --outfile=dist/index.js --platform=node",
|
|
17
17
|
"build:types": "tsc --declaration src/index.ts --emitDeclarationOnly --outDir ./dist",
|
|
18
|
-
"test": "ava tests/test.mjs --timeout=
|
|
18
|
+
"test": "ava tests/test.mjs --timeout=90s"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
21
|
"@11ty/eleventy1.0.2": "npm:@11ty/eleventy@1.0.2",
|