eleventy-test 1.0.0 → 1.2.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 +2 -1
- package/dist/debug.d.ts +2 -0
- package/dist/eleventyUtils.d.ts +3 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +87 -23
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -26,7 +26,8 @@ Want to see how it is in action? For the dogfooding fans, you can see this libra
|
|
|
26
26
|
|
|
27
27
|
const resultsAsDict = await buildScenarios({
|
|
28
28
|
projectRoot: cwd(),
|
|
29
|
-
returnArray: false
|
|
29
|
+
returnArray: false,
|
|
30
|
+
enableDebug: false
|
|
30
31
|
});
|
|
31
32
|
|
|
32
33
|
test("Check if index.html is consistent across builds", async t => {
|
package/dist/debug.d.ts
ADDED
package/dist/eleventyUtils.d.ts
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
import ScenarioOutput from "./ScenarioOutput";
|
|
2
|
+
export declare function determineInstalledEleventyVersions(projectRoot?: string): Promise<{
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}>;
|
|
2
5
|
export declare function ensureEleventyExists(projectRoot: string, eleventyVersion: string): Promise<string>;
|
|
3
6
|
export declare function buildEleventy({ eleventyVersion, scenarioDir, scenarioName, projectRoot, globalInputDir }: {
|
|
4
7
|
eleventyVersion: any;
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -21,6 +21,7 @@ var src_exports = {};
|
|
|
21
21
|
__export(src_exports, {
|
|
22
22
|
buildEleventy: () => buildEleventy,
|
|
23
23
|
buildScenarios: () => buildScenarios,
|
|
24
|
+
determineInstalledEleventyVersions: () => determineInstalledEleventyVersions,
|
|
24
25
|
ensureEleventyExists: () => ensureEleventyExists
|
|
25
26
|
});
|
|
26
27
|
module.exports = __toCommonJS(src_exports);
|
|
@@ -36,6 +37,17 @@ var import_promises = require("fs/promises");
|
|
|
36
37
|
var import_path2 = require("path");
|
|
37
38
|
var import_process = require("process");
|
|
38
39
|
|
|
40
|
+
// src/debug.ts
|
|
41
|
+
var debugEnabled = false;
|
|
42
|
+
function setDebug(enabled) {
|
|
43
|
+
debugEnabled = enabled;
|
|
44
|
+
}
|
|
45
|
+
function debug(...message) {
|
|
46
|
+
if (debugEnabled) {
|
|
47
|
+
message.forEach((msg) => console.log(msg));
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
39
51
|
// src/ScenarioOutput.ts
|
|
40
52
|
var import_path = require("path");
|
|
41
53
|
var import_fs = require("fs");
|
|
@@ -76,6 +88,9 @@ var ScenarioOutput = class {
|
|
|
76
88
|
}
|
|
77
89
|
getFileContent(filename) {
|
|
78
90
|
return new Promise(async (resolve, reject) => {
|
|
91
|
+
if (!Object.keys(this._files).includes(filename)) {
|
|
92
|
+
throw new Error(`Can't find "${filename}" in files. Available files: ${Object.keys(this._files).join(", ")}`);
|
|
93
|
+
}
|
|
79
94
|
if (!Object.keys(this.cache).includes(filename)) {
|
|
80
95
|
this.cache[filename] = this._files[filename]();
|
|
81
96
|
}
|
|
@@ -85,11 +100,39 @@ var ScenarioOutput = class {
|
|
|
85
100
|
};
|
|
86
101
|
|
|
87
102
|
// src/eleventyUtils.ts
|
|
103
|
+
async function determineInstalledEleventyVersions(projectRoot = (0, import_process.cwd)()) {
|
|
104
|
+
const eleventyPkgsDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/");
|
|
105
|
+
const versions2 = {};
|
|
106
|
+
debug("Determining installed Eleventy versions in " + eleventyPkgsDir);
|
|
107
|
+
if ((0, import_fs2.existsSync)(eleventyPkgsDir)) {
|
|
108
|
+
let eleventyPkgs = await (0, import_promises.readdir)(eleventyPkgsDir);
|
|
109
|
+
debug(`Found the followintg installed packages from @11ty: ${eleventyPkgs}`);
|
|
110
|
+
const eleventyRegex = new RegExp(/eleventy(\d|$)/m);
|
|
111
|
+
eleventyPkgs = eleventyPkgs.filter((name) => eleventyRegex.test(name));
|
|
112
|
+
debug(`Filtered non-main-eleventy packages. Results: ${eleventyPkgs}`);
|
|
113
|
+
for (let i = 0; i < eleventyPkgs.length; i++) {
|
|
114
|
+
const eleventyPkg = eleventyPkgs[i];
|
|
115
|
+
const eleventyPkgDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/", eleventyPkg);
|
|
116
|
+
const version = JSON.parse(
|
|
117
|
+
await (0, import_promises.readFile)(
|
|
118
|
+
(0, import_path2.join)(eleventyPkgDir, "package.json"),
|
|
119
|
+
{ encoding: "utf-8" }
|
|
120
|
+
)
|
|
121
|
+
).version;
|
|
122
|
+
versions2[version] = eleventyPkgDir;
|
|
123
|
+
debug(`Found ${version} at ${eleventyPkgDir}`);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return versions2;
|
|
127
|
+
}
|
|
88
128
|
async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, filename, command) {
|
|
129
|
+
debug(`Attempting to find a package manager to install Eleventy ${eleventyVersion} with`);
|
|
89
130
|
return new Promise(async (resolve, reject) => {
|
|
90
131
|
if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, filename))) {
|
|
91
132
|
try {
|
|
133
|
+
debug("Running Eleventy " + eleventyVersion);
|
|
92
134
|
(0, import_child_process.execSync)(`${command} @11ty/eleventy${eleventyVersion}@npm:@11ty/eleventy@${eleventyVersion}`, { cwd: projectRoot });
|
|
135
|
+
debug("Done running Eleventy " + eleventyVersion);
|
|
93
136
|
resolve(true);
|
|
94
137
|
} catch (e) {
|
|
95
138
|
throw e;
|
|
@@ -101,13 +144,14 @@ async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, fi
|
|
|
101
144
|
});
|
|
102
145
|
}
|
|
103
146
|
async function ensureEleventyExists(projectRoot, eleventyVersion) {
|
|
147
|
+
debug(`Ensuring Eleventy ${eleventyVersion} exists`);
|
|
104
148
|
return new Promise(async (resolve, reject) => {
|
|
105
|
-
const
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
} catch {
|
|
149
|
+
const versions2 = await determineInstalledEleventyVersions(projectRoot);
|
|
150
|
+
if (Object.keys(versions2).includes(eleventyVersion)) {
|
|
151
|
+
resolve(versions2[eleventyVersion]);
|
|
152
|
+
} else {
|
|
110
153
|
console.log(`Eleventy version ${eleventyVersion} could not be found. Installing...`);
|
|
154
|
+
const eleventyDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/eleventy" + eleventyVersion);
|
|
111
155
|
if (await installEleventyIfPkgManagerFound(
|
|
112
156
|
eleventyVersion,
|
|
113
157
|
projectRoot,
|
|
@@ -135,8 +179,11 @@ async function buildEleventy({
|
|
|
135
179
|
projectRoot = (0, import_process.cwd)(),
|
|
136
180
|
globalInputDir
|
|
137
181
|
}) {
|
|
182
|
+
debug("Running buildEleventy", "scenarioDir: " + scenarioDir, "Eleventy version: " + eleventyVersion);
|
|
138
183
|
return new Promise(async (resolve, reject) => {
|
|
184
|
+
debug("Finding package for Eleventy " + eleventyVersion);
|
|
139
185
|
const eleventyDir = await ensureEleventyExists(projectRoot, eleventyVersion);
|
|
186
|
+
debug("Found pacakge for Eleventy " + eleventyVersion);
|
|
140
187
|
const bin = JSON.parse(
|
|
141
188
|
await (0, import_promises.readFile)(
|
|
142
189
|
(0, import_path2.join)(eleventyDir, "package.json"),
|
|
@@ -144,24 +191,27 @@ async function buildEleventy({
|
|
|
144
191
|
)
|
|
145
192
|
).bin.eleventy;
|
|
146
193
|
const pathToBin = (0, import_path2.join)(eleventyDir, bin);
|
|
194
|
+
debug(`Found entrypoint for Eleventy ${eleventyVersion} at ${pathToBin}`);
|
|
147
195
|
const scenarioInputDir = (0, import_path2.join)(scenarioDir, "input");
|
|
148
196
|
let inputDir;
|
|
149
|
-
|
|
150
|
-
|
|
197
|
+
debug(`Checking whether to use scenario (${scenarioInputDir}) or global input (${globalInputDir})...`);
|
|
198
|
+
if ((0, import_fs2.existsSync)(scenarioInputDir)) {
|
|
199
|
+
debug("Using scenario input");
|
|
151
200
|
inputDir = scenarioInputDir;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
inputDir = globalInputDir;
|
|
156
|
-
} catch {
|
|
157
|
-
}
|
|
201
|
+
} else if ((0, import_fs2.existsSync)(globalInputDir)) {
|
|
202
|
+
debug("Using global input dir");
|
|
203
|
+
inputDir = globalInputDir;
|
|
158
204
|
}
|
|
205
|
+
debug("inputDir: " + inputDir);
|
|
159
206
|
if (inputDir == void 0) {
|
|
160
|
-
throw Error("inputDir is undefined!");
|
|
207
|
+
throw new Error("inputDir is undefined! Either create a global input dir or one for the scenario specifically");
|
|
161
208
|
}
|
|
162
209
|
const outputDir = (0, import_path2.join)(scenarioDir, "eleventy-test-out");
|
|
210
|
+
debug("Cleaning old test output");
|
|
163
211
|
await (0, import_promises.rm)(outputDir, { force: true, recursive: true });
|
|
212
|
+
debug("Cleaned");
|
|
164
213
|
try {
|
|
214
|
+
debug("Creating Eleventy process...");
|
|
165
215
|
const out = (0, import_child_process.fork)(
|
|
166
216
|
pathToBin,
|
|
167
217
|
["--input", inputDir, "--output", outputDir],
|
|
@@ -171,6 +221,7 @@ async function buildEleventy({
|
|
|
171
221
|
console.log(msg);
|
|
172
222
|
});
|
|
173
223
|
out.on("close", async (code) => {
|
|
224
|
+
debug(`Eleventy ${eleventyVersion}/${scenarioName} finished`);
|
|
174
225
|
resolve(new ScenarioOutput(outputDir, scenarioName));
|
|
175
226
|
});
|
|
176
227
|
} catch (e) {
|
|
@@ -180,13 +231,16 @@ async function buildEleventy({
|
|
|
180
231
|
}
|
|
181
232
|
|
|
182
233
|
// src/index.ts
|
|
234
|
+
var import_fs3 = require("fs");
|
|
183
235
|
var versions;
|
|
184
236
|
async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
185
237
|
let eleventyVersion = scenarioDirname.includes("--") ? scenarioDirname.split("--")[0] : scenarioDirname;
|
|
238
|
+
debug(`eleventyVersion from dirname: ${eleventyVersion}`);
|
|
186
239
|
if (eleventyVersion.length < 5) {
|
|
240
|
+
debug("eleventyVersion length is under 5, and as such not a full semantic version. Determining latest...");
|
|
187
241
|
const scenarioMajorVersion = scenarioDirname[0];
|
|
188
242
|
if (versions == void 0) {
|
|
189
|
-
|
|
243
|
+
debug("Pulling Eleventy tags...");
|
|
190
244
|
versions = await new Promise((resolve, reject) => {
|
|
191
245
|
(0, import_https.get)({
|
|
192
246
|
hostname: "api.github.com",
|
|
@@ -199,7 +253,7 @@ async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
|
199
253
|
res.on("data", (chunk) => {
|
|
200
254
|
data.push(chunk);
|
|
201
255
|
}).on("end", () => {
|
|
202
|
-
|
|
256
|
+
debug("Parsing Eleventy tags API response...");
|
|
203
257
|
resolve(
|
|
204
258
|
JSON.parse(
|
|
205
259
|
Buffer.concat(data).toString("utf-8")
|
|
@@ -213,30 +267,36 @@ async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
|
213
267
|
}
|
|
214
268
|
for (let i = 0; i < versions.length; i++) {
|
|
215
269
|
const version = versions[i];
|
|
270
|
+
debug("Checking " + version);
|
|
216
271
|
if (!version.name.includes("-") && version.name[1] == scenarioMajorVersion) {
|
|
217
272
|
eleventyVersion = version.name.substring(1);
|
|
273
|
+
debug("Determined latest of relevant major version for: " + eleventyVersion);
|
|
218
274
|
break;
|
|
219
275
|
}
|
|
220
276
|
}
|
|
221
277
|
}
|
|
222
278
|
return eleventyVersion;
|
|
223
279
|
}
|
|
224
|
-
async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), returnArray = true, scenariosDir = "tests/scenarios/", globalInputDir = "tests/input" }) {
|
|
280
|
+
async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), returnArray = true, scenariosDir = "tests/scenarios/", globalInputDir: passedGlobalInputDir = "tests/input", enableDebug = false }) {
|
|
281
|
+
setDebug(enableDebug);
|
|
282
|
+
debug("If you can see this, debugging has been enabled. Starting buildScenarios");
|
|
225
283
|
return new Promise(async (resolve, reject) => {
|
|
226
284
|
scenariosDir = (0, import_path3.isAbsolute)(scenariosDir) ? scenariosDir : (0, import_path3.join)(projectRoot, scenariosDir);
|
|
227
|
-
globalInputDir = (0, import_path3.isAbsolute)(
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
} catch {
|
|
231
|
-
globalInputDir = "undefined";
|
|
285
|
+
let globalInputDir = (0, import_path3.isAbsolute)(passedGlobalInputDir) ? passedGlobalInputDir : (0, import_path3.join)(projectRoot, passedGlobalInputDir);
|
|
286
|
+
if (globalInputDir) {
|
|
287
|
+
globalInputDir = (0, import_fs3.existsSync)(globalInputDir) ? globalInputDir : void 0;
|
|
232
288
|
}
|
|
289
|
+
debug(`scenariosDir: ${scenariosDir}`, `globalInputDir: ${globalInputDir}`);
|
|
233
290
|
try {
|
|
234
291
|
const scenarioDirs = await (0, import_promises2.readdir)(scenariosDir, { recursive: false, encoding: "utf-8" });
|
|
235
292
|
const scenarioOutputs = [];
|
|
293
|
+
debug(`Found scenario dirs: ${scenarioDirs}`);
|
|
236
294
|
for (let i = 0; i < scenarioDirs.length; i++) {
|
|
237
295
|
const scenarioDirname = scenarioDirs[i];
|
|
238
296
|
const scenarioDir = (0, import_path3.join)(scenariosDir, scenarioDirname);
|
|
297
|
+
debug("Parsing Eleventy version of scenario " + scenarioDirname);
|
|
239
298
|
let scenarioEleventyVersion = await scenarioDirnameToEleventyVersion(scenarioDirname);
|
|
299
|
+
debug("Determined Eleventy version: " + scenarioEleventyVersion);
|
|
240
300
|
scenarioOutputs.push(await buildEleventy({
|
|
241
301
|
eleventyVersion: scenarioEleventyVersion,
|
|
242
302
|
scenarioName: scenarioDirname,
|
|
@@ -246,8 +306,10 @@ async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), return
|
|
|
246
306
|
}));
|
|
247
307
|
}
|
|
248
308
|
if (returnArray) {
|
|
309
|
+
debug("Returning as array...");
|
|
249
310
|
resolve(scenarioOutputs);
|
|
250
311
|
} else {
|
|
312
|
+
debug("Returning as object...");
|
|
251
313
|
const returnDict = {};
|
|
252
314
|
scenarioOutputs.forEach((scenarioOutput) => {
|
|
253
315
|
returnDict[scenarioOutput.title] = scenarioOutput;
|
|
@@ -261,12 +323,14 @@ async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), return
|
|
|
261
323
|
}
|
|
262
324
|
if (require.main === module) {
|
|
263
325
|
buildScenarios({
|
|
264
|
-
projectRoot: (0, import_process2.cwd)()
|
|
326
|
+
projectRoot: (0, import_process2.cwd)(),
|
|
327
|
+
enableDebug: true
|
|
265
328
|
});
|
|
266
329
|
}
|
|
267
330
|
// Annotate the CommonJS export names for ESM import in node:
|
|
268
331
|
0 && (module.exports = {
|
|
269
332
|
buildEleventy,
|
|
270
333
|
buildScenarios,
|
|
334
|
+
determineInstalledEleventyVersions,
|
|
271
335
|
ensureEleventyExists
|
|
272
336
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-test",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Multi-configuration testing for Eleventy plugins",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "https://github.com/Denperidge/eleventy-test.git",
|
|
@@ -18,15 +18,16 @@
|
|
|
18
18
|
"test": "ava tests/test.mjs --timeout=90s"
|
|
19
19
|
},
|
|
20
20
|
"devDependencies": {
|
|
21
|
+
"@11ty/eleventy": "^3.0.0",
|
|
21
22
|
"@11ty/eleventy1.0.2": "npm:@11ty/eleventy@1.0.2",
|
|
22
23
|
"@11ty/eleventy2.0.0-canary.8": "npm:@11ty/eleventy@2.0.0-canary.8",
|
|
23
24
|
"@11ty/eleventy2.0.1": "npm:@11ty/eleventy@2.0.1",
|
|
24
|
-
"@11ty/eleventy3.0.0": "npm:@11ty/eleventy@3.0.0",
|
|
25
25
|
"@types/node": "^22.10.1",
|
|
26
26
|
"ava": "^6.2.0",
|
|
27
27
|
"esbuild": "^0.24.0",
|
|
28
28
|
"jsdom": "^25.0.1",
|
|
29
29
|
"npm-run-all": "^4.1.5",
|
|
30
30
|
"typescript": "^5.7.2"
|
|
31
|
-
}
|
|
31
|
+
},
|
|
32
|
+
"dependencies": {}
|
|
32
33
|
}
|