eleventy-test 0.1.2 → 1.1.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 +4 -1
- package/dist/index.d.ts +14 -2
- package/dist/index.js +160 -67
- package/package.json +5 -4
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,8 @@
|
|
|
1
1
|
import ScenarioOutput from "./ScenarioOutput";
|
|
2
|
-
export declare function
|
|
2
|
+
export declare function determineInstalledEleventyVersions(projectRoot?: string): Promise<{
|
|
3
|
+
[key: string]: string;
|
|
4
|
+
}>;
|
|
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;
|
|
5
8
|
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
|
@@ -21,16 +21,19 @@ 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);
|
|
27
28
|
var import_process2 = require("process");
|
|
28
29
|
var import_path3 = require("path");
|
|
29
|
-
var
|
|
30
|
+
var import_promises2 = require("fs/promises");
|
|
31
|
+
var import_https = require("https");
|
|
30
32
|
|
|
31
33
|
// src/eleventyUtils.ts
|
|
32
34
|
var import_child_process = require("child_process");
|
|
33
35
|
var import_fs2 = require("fs");
|
|
36
|
+
var import_promises = require("fs/promises");
|
|
34
37
|
var import_path2 = require("path");
|
|
35
38
|
var import_process = require("process");
|
|
36
39
|
|
|
@@ -73,37 +76,76 @@ var ScenarioOutput = class {
|
|
|
73
76
|
return this._files;
|
|
74
77
|
}
|
|
75
78
|
getFileContent(filename) {
|
|
76
|
-
|
|
77
|
-
this.cache
|
|
78
|
-
|
|
79
|
-
|
|
79
|
+
return new Promise(async (resolve, reject) => {
|
|
80
|
+
if (!Object.keys(this.cache).includes(filename)) {
|
|
81
|
+
this.cache[filename] = this._files[filename]();
|
|
82
|
+
}
|
|
83
|
+
resolve(this.cache[filename]);
|
|
84
|
+
});
|
|
80
85
|
}
|
|
81
86
|
};
|
|
82
87
|
|
|
83
88
|
// src/eleventyUtils.ts
|
|
84
|
-
function
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
async function determineInstalledEleventyVersions(projectRoot = (0, import_process.cwd)()) {
|
|
90
|
+
let eleventyPkgs = await (0, import_promises.readdir)((0, import_path2.join)(projectRoot, "node_modules/@11ty/"));
|
|
91
|
+
const eleventyRegex = new RegExp(/eleventy(\d|$)/m);
|
|
92
|
+
eleventyPkgs = eleventyPkgs.filter((name) => eleventyRegex.test(name));
|
|
93
|
+
const versions2 = {};
|
|
94
|
+
for (let i = 0; i < eleventyPkgs.length; i++) {
|
|
95
|
+
const eleventyPkg = eleventyPkgs[i];
|
|
96
|
+
const eleventyPkgDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/", eleventyPkg);
|
|
97
|
+
const version = JSON.parse(
|
|
98
|
+
await (0, import_promises.readFile)(
|
|
99
|
+
(0, import_path2.join)(eleventyPkgDir, "package.json"),
|
|
100
|
+
{ encoding: "utf-8" }
|
|
101
|
+
)
|
|
102
|
+
).version;
|
|
103
|
+
versions2[version] = eleventyPkgDir;
|
|
90
104
|
}
|
|
105
|
+
return versions2;
|
|
91
106
|
}
|
|
92
|
-
function
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
installEleventy(eleventyVersion, projectRoot, "yarn add -D");
|
|
107
|
+
async function installEleventyIfPkgManagerFound(eleventyVersion, projectRoot, filename, command) {
|
|
108
|
+
return new Promise(async (resolve, reject) => {
|
|
109
|
+
if ((0, import_fs2.existsSync)((0, import_path2.join)(projectRoot, filename))) {
|
|
110
|
+
try {
|
|
111
|
+
(0, import_child_process.execSync)(`${command} @11ty/eleventy${eleventyVersion}@npm:@11ty/eleventy@${eleventyVersion}`, { cwd: projectRoot });
|
|
112
|
+
resolve(true);
|
|
113
|
+
} catch (e) {
|
|
114
|
+
throw e;
|
|
115
|
+
}
|
|
102
116
|
} else {
|
|
103
|
-
|
|
117
|
+
console.error(`Couldn't detect ${filename}, skipping ${command.split(" ")[0]}...`);
|
|
118
|
+
resolve(false);
|
|
104
119
|
}
|
|
105
|
-
|
|
106
|
-
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
async function ensureEleventyExists(projectRoot, eleventyVersion) {
|
|
123
|
+
return new Promise(async (resolve, reject) => {
|
|
124
|
+
const versions2 = await determineInstalledEleventyVersions(projectRoot);
|
|
125
|
+
if (Object.keys(versions2).includes(eleventyVersion)) {
|
|
126
|
+
resolve(versions2[eleventyVersion]);
|
|
127
|
+
} else {
|
|
128
|
+
console.log(`Eleventy version ${eleventyVersion} could not be found. Installing...`);
|
|
129
|
+
const eleventyDir = (0, import_path2.join)(projectRoot, "node_modules/@11ty/eleventy" + eleventyVersion);
|
|
130
|
+
if (await installEleventyIfPkgManagerFound(
|
|
131
|
+
eleventyVersion,
|
|
132
|
+
projectRoot,
|
|
133
|
+
"package-lock.json",
|
|
134
|
+
"npm install --save-dev"
|
|
135
|
+
)) {
|
|
136
|
+
resolve(eleventyDir);
|
|
137
|
+
} else if (await installEleventyIfPkgManagerFound(
|
|
138
|
+
eleventyVersion,
|
|
139
|
+
projectRoot,
|
|
140
|
+
"yarn.lock",
|
|
141
|
+
"yarn add -D"
|
|
142
|
+
)) {
|
|
143
|
+
resolve(eleventyDir);
|
|
144
|
+
} else {
|
|
145
|
+
throw new Error(`Error while installing eleventy${eleventyVersion}: Could not determine package manager`);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
});
|
|
107
149
|
}
|
|
108
150
|
async function buildEleventy({
|
|
109
151
|
eleventyVersion,
|
|
@@ -112,22 +154,32 @@ async function buildEleventy({
|
|
|
112
154
|
projectRoot = (0, import_process.cwd)(),
|
|
113
155
|
globalInputDir
|
|
114
156
|
}) {
|
|
115
|
-
return new Promise((resolve, reject) => {
|
|
116
|
-
const eleventyDir = ensureEleventyExists(projectRoot, eleventyVersion);
|
|
157
|
+
return new Promise(async (resolve, reject) => {
|
|
158
|
+
const eleventyDir = await ensureEleventyExists(projectRoot, eleventyVersion);
|
|
117
159
|
const bin = JSON.parse(
|
|
118
|
-
(0,
|
|
160
|
+
await (0, import_promises.readFile)(
|
|
119
161
|
(0, import_path2.join)(eleventyDir, "package.json"),
|
|
120
162
|
{ encoding: "utf-8" }
|
|
121
163
|
)
|
|
122
164
|
).bin.eleventy;
|
|
123
165
|
const pathToBin = (0, import_path2.join)(eleventyDir, bin);
|
|
124
166
|
const scenarioInputDir = (0, import_path2.join)(scenarioDir, "input");
|
|
125
|
-
|
|
167
|
+
let inputDir;
|
|
168
|
+
try {
|
|
169
|
+
await (0, import_promises.access)(scenarioInputDir);
|
|
170
|
+
inputDir = scenarioInputDir;
|
|
171
|
+
} catch {
|
|
172
|
+
try {
|
|
173
|
+
await (0, import_promises.access)(globalInputDir);
|
|
174
|
+
inputDir = globalInputDir;
|
|
175
|
+
} catch {
|
|
176
|
+
}
|
|
177
|
+
}
|
|
126
178
|
if (inputDir == void 0) {
|
|
127
179
|
throw Error("inputDir is undefined!");
|
|
128
180
|
}
|
|
129
181
|
const outputDir = (0, import_path2.join)(scenarioDir, "eleventy-test-out");
|
|
130
|
-
(0,
|
|
182
|
+
await (0, import_promises.rm)(outputDir, { force: true, recursive: true });
|
|
131
183
|
try {
|
|
132
184
|
const out = (0, import_child_process.fork)(
|
|
133
185
|
pathToBin,
|
|
@@ -137,9 +189,8 @@ async function buildEleventy({
|
|
|
137
189
|
out.on("message", (msg) => {
|
|
138
190
|
console.log(msg);
|
|
139
191
|
});
|
|
140
|
-
out.on("close", (code) => {
|
|
141
|
-
|
|
142
|
-
resolve(output);
|
|
192
|
+
out.on("close", async (code) => {
|
|
193
|
+
resolve(new ScenarioOutput(outputDir, scenarioName));
|
|
143
194
|
});
|
|
144
195
|
} catch (e) {
|
|
145
196
|
throw e;
|
|
@@ -148,52 +199,94 @@ async function buildEleventy({
|
|
|
148
199
|
}
|
|
149
200
|
|
|
150
201
|
// 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;
|
|
202
|
+
var versions;
|
|
203
|
+
async function scenarioDirnameToEleventyVersion(scenarioDirname) {
|
|
204
|
+
let eleventyVersion = scenarioDirname.includes("--") ? scenarioDirname.split("--")[0] : scenarioDirname;
|
|
205
|
+
if (eleventyVersion.length < 5) {
|
|
206
|
+
const scenarioMajorVersion = scenarioDirname[0];
|
|
207
|
+
if (versions == void 0) {
|
|
208
|
+
console.log("Pulling Eleventy tags...");
|
|
209
|
+
versions = await new Promise((resolve, reject) => {
|
|
210
|
+
(0, import_https.get)({
|
|
211
|
+
hostname: "api.github.com",
|
|
212
|
+
path: "/repos/11ty/eleventy/tags",
|
|
213
|
+
headers: {
|
|
214
|
+
"User-Agent": "Mozilla/5.0"
|
|
169
215
|
}
|
|
170
|
-
}
|
|
216
|
+
}, (res) => {
|
|
217
|
+
let data = [];
|
|
218
|
+
res.on("data", (chunk) => {
|
|
219
|
+
data.push(chunk);
|
|
220
|
+
}).on("end", () => {
|
|
221
|
+
console.log("Parsing API response...");
|
|
222
|
+
resolve(
|
|
223
|
+
JSON.parse(
|
|
224
|
+
Buffer.concat(data).toString("utf-8")
|
|
225
|
+
)
|
|
226
|
+
);
|
|
227
|
+
}).on("error", (err) => {
|
|
228
|
+
throw err;
|
|
229
|
+
});
|
|
230
|
+
});
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
for (let i = 0; i < versions.length; i++) {
|
|
234
|
+
const version = versions[i];
|
|
235
|
+
if (!version.name.includes("-") && version.name[1] == scenarioMajorVersion) {
|
|
236
|
+
eleventyVersion = version.name.substring(1);
|
|
237
|
+
break;
|
|
171
238
|
}
|
|
172
|
-
scenarioOutputs.push(await buildEleventy({
|
|
173
|
-
eleventyVersion: scenarioEleventyVersion,
|
|
174
|
-
scenarioName: scenarioDirname,
|
|
175
|
-
globalInputDir,
|
|
176
|
-
projectRoot,
|
|
177
|
-
scenarioDir
|
|
178
|
-
}));
|
|
179
239
|
}
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
240
|
+
}
|
|
241
|
+
return eleventyVersion;
|
|
242
|
+
}
|
|
243
|
+
async function buildScenarios({ projectRoot = (0, import_process2.cwd)(), returnArray = true, scenariosDir = "tests/scenarios/", globalInputDir = "tests/input" }) {
|
|
244
|
+
return new Promise(async (resolve, reject) => {
|
|
245
|
+
scenariosDir = (0, import_path3.isAbsolute)(scenariosDir) ? scenariosDir : (0, import_path3.join)(projectRoot, scenariosDir);
|
|
246
|
+
globalInputDir = (0, import_path3.isAbsolute)(globalInputDir) ? globalInputDir : (0, import_path3.join)(projectRoot, globalInputDir);
|
|
247
|
+
try {
|
|
248
|
+
await (0, import_promises2.access)(globalInputDir);
|
|
249
|
+
} catch {
|
|
250
|
+
globalInputDir = "undefined";
|
|
251
|
+
}
|
|
252
|
+
try {
|
|
253
|
+
const scenarioDirs = await (0, import_promises2.readdir)(scenariosDir, { recursive: false, encoding: "utf-8" });
|
|
254
|
+
const scenarioOutputs = [];
|
|
255
|
+
for (let i = 0; i < scenarioDirs.length; i++) {
|
|
256
|
+
const scenarioDirname = scenarioDirs[i];
|
|
257
|
+
const scenarioDir = (0, import_path3.join)(scenariosDir, scenarioDirname);
|
|
258
|
+
let scenarioEleventyVersion = await scenarioDirnameToEleventyVersion(scenarioDirname);
|
|
259
|
+
scenarioOutputs.push(await buildEleventy({
|
|
260
|
+
eleventyVersion: scenarioEleventyVersion,
|
|
261
|
+
scenarioName: scenarioDirname,
|
|
262
|
+
globalInputDir,
|
|
263
|
+
projectRoot,
|
|
264
|
+
scenarioDir
|
|
265
|
+
}));
|
|
266
|
+
}
|
|
267
|
+
if (returnArray) {
|
|
268
|
+
resolve(scenarioOutputs);
|
|
269
|
+
} else {
|
|
270
|
+
const returnDict = {};
|
|
271
|
+
scenarioOutputs.forEach((scenarioOutput) => {
|
|
272
|
+
returnDict[scenarioOutput.title] = scenarioOutput;
|
|
273
|
+
});
|
|
274
|
+
resolve(returnDict);
|
|
275
|
+
}
|
|
276
|
+
} catch (e) {
|
|
277
|
+
throw e;
|
|
188
278
|
}
|
|
189
279
|
});
|
|
190
280
|
}
|
|
191
281
|
if (require.main === module) {
|
|
192
|
-
buildScenarios(
|
|
282
|
+
buildScenarios({
|
|
283
|
+
projectRoot: (0, import_process2.cwd)()
|
|
284
|
+
});
|
|
193
285
|
}
|
|
194
286
|
// Annotate the CommonJS export names for ESM import in node:
|
|
195
287
|
0 && (module.exports = {
|
|
196
288
|
buildEleventy,
|
|
197
289
|
buildScenarios,
|
|
290
|
+
determineInstalledEleventyVersions,
|
|
198
291
|
ensureEleventyExists
|
|
199
292
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eleventy-test",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.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,18 +15,19 @@
|
|
|
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
|
+
"@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
|
}
|