eleventy-test 1.1.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/index.d.ts +1 -0
- package/dist/index.js +75 -31
- package/package.json +1 -1
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/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -37,6 +37,17 @@ var import_promises = require("fs/promises");
|
|
|
37
37
|
var import_path2 = require("path");
|
|
38
38
|
var import_process = require("process");
|
|
39
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
|
+
|
|
40
51
|
// src/ScenarioOutput.ts
|
|
41
52
|
var import_path = require("path");
|
|
42
53
|
var import_fs = require("fs");
|
|
@@ -77,6 +88,9 @@ var ScenarioOutput = class {
|
|
|
77
88
|
}
|
|
78
89
|
getFileContent(filename) {
|
|
79
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
|
+
}
|
|
80
94
|
if (!Object.keys(this.cache).includes(filename)) {
|
|
81
95
|
this.cache[filename] = this._files[filename]();
|
|
82
96
|
}
|
|
@@ -87,28 +101,38 @@ var ScenarioOutput = class {
|
|
|
87
101
|
|
|
88
102
|
// src/eleventyUtils.ts
|
|
89
103
|
async function determineInstalledEleventyVersions(projectRoot = (0, import_process.cwd)()) {
|
|
90
|
-
|
|
91
|
-
const eleventyRegex = new RegExp(/eleventy(\d|$)/m);
|
|
92
|
-
eleventyPkgs = eleventyPkgs.filter((name) => eleventyRegex.test(name));
|
|
104
|
+
const eleventyPkgsDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/");
|
|
93
105
|
const versions2 = {};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
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
|
+
}
|
|
104
125
|
}
|
|
105
126
|
return versions2;
|
|
106
127
|
}
|
|
107
128
|
async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, filename, command) {
|
|
129
|
+
debug(`Attempting to find a package manager to install Eleventy ${eleventyVersion} with`);
|
|
108
130
|
return new Promise(async (resolve, reject) => {
|
|
109
131
|
if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, filename))) {
|
|
110
132
|
try {
|
|
133
|
+
debug("Running Eleventy " + eleventyVersion);
|
|
111
134
|
(0, import_child_process.execSync)(`${command} @11ty/eleventy${eleventyVersion}@npm:@11ty/eleventy@${eleventyVersion}`, { cwd: projectRoot });
|
|
135
|
+
debug("Done running Eleventy " + eleventyVersion);
|
|
112
136
|
resolve(true);
|
|
113
137
|
} catch (e) {
|
|
114
138
|
throw e;
|
|
@@ -120,6 +144,7 @@ async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, fi
|
|
|
120
144
|
});
|
|
121
145
|
}
|
|
122
146
|
async function ensureEleventyExists(projectRoot, eleventyVersion) {
|
|
147
|
+
debug(`Ensuring Eleventy ${eleventyVersion} exists`);
|
|
123
148
|
return new Promise(async (resolve, reject) => {
|
|
124
149
|
const versions2 = await determineInstalledEleventyVersions(projectRoot);
|
|
125
150
|
if (Object.keys(versions2).includes(eleventyVersion)) {
|
|
@@ -154,8 +179,11 @@ async function buildEleventy({
|
|
|
154
179
|
projectRoot = (0, import_process.cwd)(),
|
|
155
180
|
globalInputDir
|
|
156
181
|
}) {
|
|
182
|
+
debug("Running buildEleventy", "scenarioDir: " + scenarioDir, "Eleventy version: " + eleventyVersion);
|
|
157
183
|
return new Promise(async (resolve, reject) => {
|
|
184
|
+
debug("Finding package for Eleventy " + eleventyVersion);
|
|
158
185
|
const eleventyDir = await ensureEleventyExists(projectRoot, eleventyVersion);
|
|
186
|
+
debug("Found pacakge for Eleventy " + eleventyVersion);
|
|
159
187
|
const bin = JSON.parse(
|
|
160
188
|
await (0, import_promises.readFile)(
|
|
161
189
|
(0, import_path2.join)(eleventyDir, "package.json"),
|
|
@@ -163,24 +191,27 @@ async function buildEleventy({
|
|
|
163
191
|
)
|
|
164
192
|
).bin.eleventy;
|
|
165
193
|
const pathToBin = (0, import_path2.join)(eleventyDir, bin);
|
|
194
|
+
debug(`Found entrypoint for Eleventy ${eleventyVersion} at ${pathToBin}`);
|
|
166
195
|
const scenarioInputDir = (0, import_path2.join)(scenarioDir, "input");
|
|
167
196
|
let inputDir;
|
|
168
|
-
|
|
169
|
-
|
|
197
|
+
debug(`Checking whether to use scenario (${scenarioInputDir}) or global input (${globalInputDir})...`);
|
|
198
|
+
if ((0, import_fs2.existsSync)(scenarioInputDir)) {
|
|
199
|
+
debug("Using scenario input");
|
|
170
200
|
inputDir = scenarioInputDir;
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
inputDir = globalInputDir;
|
|
175
|
-
} catch {
|
|
176
|
-
}
|
|
201
|
+
} else if ((0, import_fs2.existsSync)(globalInputDir)) {
|
|
202
|
+
debug("Using global input dir");
|
|
203
|
+
inputDir = globalInputDir;
|
|
177
204
|
}
|
|
205
|
+
debug("inputDir: " + inputDir);
|
|
178
206
|
if (inputDir == void 0) {
|
|
179
|
-
throw Error("inputDir is undefined!");
|
|
207
|
+
throw new Error("inputDir is undefined! Either create a global input dir or one for the scenario specifically");
|
|
180
208
|
}
|
|
181
209
|
const outputDir = (0, import_path2.join)(scenarioDir, "eleventy-test-out");
|
|
210
|
+
debug("Cleaning old test output");
|
|
182
211
|
await (0, import_promises.rm)(outputDir, { force: true, recursive: true });
|
|
212
|
+
debug("Cleaned");
|
|
183
213
|
try {
|
|
214
|
+
debug("Creating Eleventy process...");
|
|
184
215
|
const out = (0, import_child_process.fork)(
|
|
185
216
|
pathToBin,
|
|
186
217
|
["--input", inputDir, "--output", outputDir],
|
|
@@ -190,6 +221,7 @@ async function buildEleventy({
|
|
|
190
221
|
console.log(msg);
|
|
191
222
|
});
|
|
192
223
|
out.on("close", async (code) => {
|
|
224
|
+
debug(`Eleventy ${eleventyVersion}/${scenarioName} finished`);
|
|
193
225
|
resolve(new ScenarioOutput(outputDir, scenarioName));
|
|
194
226
|
});
|
|
195
227
|
} catch (e) {
|
|
@@ -199,13 +231,16 @@ async function buildEleventy({
|
|
|
199
231
|
}
|
|
200
232
|
|
|
201
233
|
// src/index.ts
|
|
234
|
+
var import_fs3 = require("fs");
|
|
202
235
|
var versions;
|
|
203
236
|
async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
204
237
|
let eleventyVersion = scenarioDirname.includes("--") ? scenarioDirname.split("--")[0] : scenarioDirname;
|
|
238
|
+
debug(`eleventyVersion from dirname: ${eleventyVersion}`);
|
|
205
239
|
if (eleventyVersion.length < 5) {
|
|
240
|
+
debug("eleventyVersion length is under 5, and as such not a full semantic version. Determining latest...");
|
|
206
241
|
const scenarioMajorVersion = scenarioDirname[0];
|
|
207
242
|
if (versions == void 0) {
|
|
208
|
-
|
|
243
|
+
debug("Pulling Eleventy tags...");
|
|
209
244
|
versions = await new Promise((resolve, reject) => {
|
|
210
245
|
(0, import_https.get)({
|
|
211
246
|
hostname: "api.github.com",
|
|
@@ -218,7 +253,7 @@ async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
|
218
253
|
res.on("data", (chunk) => {
|
|
219
254
|
data.push(chunk);
|
|
220
255
|
}).on("end", () => {
|
|
221
|
-
|
|
256
|
+
debug("Parsing Eleventy tags API response...");
|
|
222
257
|
resolve(
|
|
223
258
|
JSON.parse(
|
|
224
259
|
Buffer.concat(data).toString("utf-8")
|
|
@@ -232,30 +267,36 @@ async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
|
232
267
|
}
|
|
233
268
|
for (let i = 0; i < versions.length; i++) {
|
|
234
269
|
const version = versions[i];
|
|
270
|
+
debug("Checking " + version);
|
|
235
271
|
if (!version.name.includes("-") && version.name[1] == scenarioMajorVersion) {
|
|
236
272
|
eleventyVersion = version.name.substring(1);
|
|
273
|
+
debug("Determined latest of relevant major version for: " + eleventyVersion);
|
|
237
274
|
break;
|
|
238
275
|
}
|
|
239
276
|
}
|
|
240
277
|
}
|
|
241
278
|
return eleventyVersion;
|
|
242
279
|
}
|
|
243
|
-
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");
|
|
244
283
|
return new Promise(async (resolve, reject) => {
|
|
245
284
|
scenariosDir = (0, import_path3.isAbsolute)(scenariosDir) ? scenariosDir : (0, import_path3.join)(projectRoot, scenariosDir);
|
|
246
|
-
globalInputDir = (0, import_path3.isAbsolute)(
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
} catch {
|
|
250
|
-
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;
|
|
251
288
|
}
|
|
289
|
+
debug(`scenariosDir: ${scenariosDir}`, `globalInputDir: ${globalInputDir}`);
|
|
252
290
|
try {
|
|
253
291
|
const scenarioDirs = await (0, import_promises2.readdir)(scenariosDir, { recursive: false, encoding: "utf-8" });
|
|
254
292
|
const scenarioOutputs = [];
|
|
293
|
+
debug(`Found scenario dirs: ${scenarioDirs}`);
|
|
255
294
|
for (let i = 0; i < scenarioDirs.length; i++) {
|
|
256
295
|
const scenarioDirname = scenarioDirs[i];
|
|
257
296
|
const scenarioDir = (0, import_path3.join)(scenariosDir, scenarioDirname);
|
|
297
|
+
debug("Parsing Eleventy version of scenario " + scenarioDirname);
|
|
258
298
|
let scenarioEleventyVersion = await scenarioDirnameToEleventyVersion(scenarioDirname);
|
|
299
|
+
debug("Determined Eleventy version: " + scenarioEleventyVersion);
|
|
259
300
|
scenarioOutputs.push(await buildEleventy({
|
|
260
301
|
eleventyVersion: scenarioEleventyVersion,
|
|
261
302
|
scenarioName: scenarioDirname,
|
|
@@ -265,8 +306,10 @@ async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), return
|
|
|
265
306
|
}));
|
|
266
307
|
}
|
|
267
308
|
if (returnArray) {
|
|
309
|
+
debug("Returning as array...");
|
|
268
310
|
resolve(scenarioOutputs);
|
|
269
311
|
} else {
|
|
312
|
+
debug("Returning as object...");
|
|
270
313
|
const returnDict = {};
|
|
271
314
|
scenarioOutputs.forEach((scenarioOutput) => {
|
|
272
315
|
returnDict[scenarioOutput.title] = scenarioOutput;
|
|
@@ -280,7 +323,8 @@ async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), return
|
|
|
280
323
|
}
|
|
281
324
|
if (require.main === module) {
|
|
282
325
|
buildScenarios({
|
|
283
|
-
projectRoot: (0, import_process2.cwd)()
|
|
326
|
+
projectRoot: (0, import_process2.cwd)(),
|
|
327
|
+
enableDebug: true
|
|
284
328
|
});
|
|
285
329
|
}
|
|
286
330
|
// Annotate the CommonJS export names for ESM import in node:
|