@rettangoli/vt 0.0.1 → 0.0.2-rc1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rettangoli/vt",
3
- "version": "0.0.1",
3
+ "version": "0.0.2-rc1",
4
4
  "description": "Rettangoli Visual Testing",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/cli/accept.js CHANGED
@@ -34,7 +34,7 @@ async function copyWebpFiles(sourceDir, destDir) {
34
34
  */
35
35
  async function acceptReference(options = {}) {
36
36
  const {
37
- vizPath = "./viz",
37
+ vizPath = "./vt",
38
38
  } = options;
39
39
 
40
40
  const referenceDir = join(vizPath, "reference");
@@ -94,7 +94,7 @@ async function main(options) {
94
94
  );
95
95
  } finally {
96
96
  // Stop server
97
- server.stop();
97
+ server.close();
98
98
  console.log("Server stopped");
99
99
  }
100
100
  }
package/src/common.js CHANGED
@@ -5,8 +5,10 @@ import {
5
5
  writeFileSync,
6
6
  mkdirSync,
7
7
  existsSync,
8
+ unlinkSync,
8
9
  } from "fs";
9
10
  import { join, dirname, resolve, extname } from "path";
11
+ import http from "http";
10
12
  import { load as loadYaml } from "js-yaml";
11
13
  import { Liquid } from "liquidjs";
12
14
  import { chromium } from "playwright";
@@ -181,49 +183,47 @@ async function generateHtml(specsDir, templatePath, outputDir) {
181
183
  * Start a web server to serve static files
182
184
  */
183
185
  function startWebServer(artifactsDir, staticDir, port) {
184
- const server = Bun.serve({
185
- port: port,
186
- fetch(req) {
187
- const url = new URL(req.url);
188
- let path = url.pathname;
189
-
190
- // Default to index.html for root path
191
- if (path === "/") {
192
- path = "/index.html";
193
- }
186
+ const server = http.createServer((req, res) => {
187
+ const url = new URL(req.url, `http://localhost:${port}`);
188
+ let path = url.pathname;
194
189
 
195
- // Remove leading slash for file path
196
- const filePath = path.startsWith("/") ? path.slice(1) : path;
190
+ // Default to index.html for root path
191
+ if (path === "/") {
192
+ path = "/index.html";
193
+ }
197
194
 
198
- // Try to serve from artifacts directory first
199
- const artifactsPath = join(artifactsDir, filePath);
200
- if (existsSync(artifactsPath) && statSync(artifactsPath).isFile()) {
201
- const fileContent = readFileSync(artifactsPath);
202
- const contentType = getContentType(artifactsPath);
203
- return new Response(fileContent, {
204
- headers: { "Content-Type": contentType },
205
- });
206
- }
195
+ // Remove leading slash for file path
196
+ const filePath = path.startsWith("/") ? path.slice(1) : path;
197
+
198
+ // Try to serve from artifacts directory first
199
+ const artifactsPath = join(artifactsDir, filePath);
200
+ if (existsSync(artifactsPath) && statSync(artifactsPath).isFile()) {
201
+ const fileContent = readFileSync(artifactsPath);
202
+ const contentType = getContentType(artifactsPath);
203
+ res.writeHead(200, { "Content-Type": contentType });
204
+ res.end(fileContent);
205
+ return;
206
+ }
207
207
 
208
- // Then try to serve from static directory
209
- const staticPath = join(staticDir, filePath);
210
- if (existsSync(staticPath) && statSync(staticPath).isFile()) {
211
- const fileContent = readFileSync(staticPath);
212
- const contentType = getContentType(staticPath);
213
- return new Response(fileContent, {
214
- headers: { "Content-Type": contentType },
215
- });
216
- }
208
+ // Then try to serve from static directory
209
+ const staticPath = join(staticDir, filePath);
210
+ if (existsSync(staticPath) && statSync(staticPath).isFile()) {
211
+ const fileContent = readFileSync(staticPath);
212
+ const contentType = getContentType(staticPath);
213
+ res.writeHead(200, { "Content-Type": contentType });
214
+ res.end(fileContent);
215
+ return;
216
+ }
217
217
 
218
- // If not found in either directory, return 404
219
- return new Response("Not Found", {
220
- status: 404,
221
- headers: { "Content-Type": "text/plain" },
222
- });
223
- },
218
+ // If not found in either directory, return 404
219
+ res.writeHead(404, { "Content-Type": "text/plain" });
220
+ res.end("Not Found");
224
221
  });
225
222
 
226
- console.log(`Server started at http://localhost:${port}`);
223
+ server.listen(port, () => {
224
+ console.log(`Server started at http://localhost:${port}`);
225
+ });
226
+
227
227
  return server;
228
228
  }
229
229
 
@@ -311,7 +311,7 @@ async function takeScreenshots(
311
311
 
312
312
  // Remove temporary PNG file
313
313
  if (existsSync(tempPngPath)) {
314
- await import('fs').then(fs => fs.promises.unlink(tempPngPath));
314
+ unlinkSync(tempPngPath);
315
315
  }
316
316
 
317
317
  // example instructions:
@@ -350,7 +350,7 @@ async function takeScreenshots(
350
350
 
351
351
  // Remove temporary PNG file
352
352
  if (existsSync(tempAdditionalPngPath)) {
353
- await import('fs').then(fs => fs.promises.unlink(tempAdditionalPngPath));
353
+ unlinkSync(tempAdditionalPngPath);
354
354
  }
355
355
 
356
356
  console.log(