From 8efdcf45c00f7cb471deab01f65fe93e1b539d44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Philippe=20Rivi=C3=A8re?= Date: Fri, 22 Nov 2024 18:25:17 +0100 Subject: [PATCH] in build tests, sort by extension then path (#1809) * sort by extension then path this fixes the wobbling tests (duckdb, sql, npm) that change when a commit modifies the content hash of inputs.js vs inputs.css * win32 * adjust sort order to minimize churn * remove unused import --------- Co-authored-by: Mike Bostock --- test/build-test.ts | 8 ++++++-- .../{duckdb.00000005.js => duckdb.00000004.js} | 0 .../_observablehq/stdlib/inputs.00000005.js | 0 .../_observablehq/stdlib/inputs.00000006.css | 0 ...006.js => theme-air,near-midnight.00000007.css} | 0 test/output/build/duckdb/index.html | 12 ++++++------ test/output/build/npm/_import/index.4bdc071f.js | 2 +- .../_observablehq/stdlib/inputs.00000004.js} | 0 .../_observablehq/stdlib/inputs.00000005.css} | 0 ...04.css => theme-air,near-midnight.00000006.css} | 0 test/output/build/npm/index.html | 10 +++++----- .../{duckdb.00000005.js => duckdb.00000004.js} | 0 .../{inputs.00000006.js => inputs.00000005.js} | 0 .../{inputs.00000007.css => inputs.00000006.css} | 0 ...04.css => theme-air,near-midnight.00000007.css} | 0 test/output/build/sql/index.html | 14 +++++++------- 16 files changed, 25 insertions(+), 21 deletions(-) rename test/output/build/duckdb/_observablehq/stdlib/{duckdb.00000005.js => duckdb.00000004.js} (100%) rename test/output/build/{npm => duckdb}/_observablehq/stdlib/inputs.00000005.js (100%) rename test/output/build/{npm => duckdb}/_observablehq/stdlib/inputs.00000006.css (100%) rename test/output/build/duckdb/_observablehq/{stdlib/inputs.00000006.js => theme-air,near-midnight.00000007.css} (100%) rename test/output/build/{duckdb/_observablehq/stdlib/inputs.00000007.css => npm/_observablehq/stdlib/inputs.00000004.js} (100%) rename test/output/build/{duckdb/_observablehq/theme-air,near-midnight.00000004.css => npm/_observablehq/stdlib/inputs.00000005.css} (100%) rename test/output/build/npm/_observablehq/{theme-air,near-midnight.00000004.css => theme-air,near-midnight.00000006.css} (100%) rename test/output/build/sql/_observablehq/stdlib/{duckdb.00000005.js => duckdb.00000004.js} (100%) rename test/output/build/sql/_observablehq/stdlib/{inputs.00000006.js => inputs.00000005.js} (100%) rename test/output/build/sql/_observablehq/stdlib/{inputs.00000007.css => inputs.00000006.css} (100%) rename test/output/build/sql/_observablehq/{theme-air,near-midnight.00000004.css => theme-air,near-midnight.00000007.css} (100%) diff --git a/test/build-test.ts b/test/build-test.ts index b477d58fd..aade58fd6 100644 --- a/test/build-test.ts +++ b/test/build-test.ts @@ -2,9 +2,10 @@ import assert from "node:assert"; import {existsSync, readdirSync, statSync} from "node:fs"; import {mkdir, mkdtemp, open, readFile, rename, rm, unlink, writeFile} from "node:fs/promises"; import os from "node:os"; +import {extname} from "node:path/posix"; import {join, normalize, relative} from "node:path/posix"; import {PassThrough} from "node:stream"; -import {ascending, difference} from "d3-array"; +import {ascending, difference, sort} from "d3-array"; import type {BuildManifest} from "../src/build.js"; import {FileBuildEffects, build} from "../src/build.js"; import {normalizeConfig, readConfig, setCurrentDate} from "../src/config.js"; @@ -76,7 +77,10 @@ describe("build", () => { // renumber the hashes so they are sequential. This way we don’t have to // update the test snapshots whenever Framework’s client code changes. We // make an exception for minisearch.json because to test the content. - for (const path of findFiles(join(outputDir, "_observablehq"))) { + for (const path of sort( + findFiles(join(outputDir, "_observablehq")), + (a, b) => ascending(extname(a) === ".css", extname(b) === ".css") || ascending(a, b) + )) { const match = /^((.+)\.[0-9a-f]{8})\.(\w+)$/.exec(path); if (!match) throw new Error(`no hash found: ${path}`); const [, key, name, ext] = match; diff --git a/test/output/build/duckdb/_observablehq/stdlib/duckdb.00000005.js b/test/output/build/duckdb/_observablehq/stdlib/duckdb.00000004.js similarity index 100% rename from test/output/build/duckdb/_observablehq/stdlib/duckdb.00000005.js rename to test/output/build/duckdb/_observablehq/stdlib/duckdb.00000004.js diff --git a/test/output/build/npm/_observablehq/stdlib/inputs.00000005.js b/test/output/build/duckdb/_observablehq/stdlib/inputs.00000005.js similarity index 100% rename from test/output/build/npm/_observablehq/stdlib/inputs.00000005.js rename to test/output/build/duckdb/_observablehq/stdlib/inputs.00000005.js diff --git a/test/output/build/npm/_observablehq/stdlib/inputs.00000006.css b/test/output/build/duckdb/_observablehq/stdlib/inputs.00000006.css similarity index 100% rename from test/output/build/npm/_observablehq/stdlib/inputs.00000006.css rename to test/output/build/duckdb/_observablehq/stdlib/inputs.00000006.css diff --git a/test/output/build/duckdb/_observablehq/stdlib/inputs.00000006.js b/test/output/build/duckdb/_observablehq/theme-air,near-midnight.00000007.css similarity index 100% rename from test/output/build/duckdb/_observablehq/stdlib/inputs.00000006.js rename to test/output/build/duckdb/_observablehq/theme-air,near-midnight.00000007.css diff --git a/test/output/build/duckdb/index.html b/test/output/build/duckdb/index.html index b0ceaf67b..d470ee724 100644 --- a/test/output/build/duckdb/index.html +++ b/test/output/build/duckdb/index.html @@ -7,16 +7,16 @@ test DuckDB - - + + - - + + - - + + diff --git a/test/output/build/npm/_import/index.4bdc071f.js b/test/output/build/npm/_import/index.4bdc071f.js index 108b15a25..bddccaad0 100644 --- a/test/output/build/npm/_import/index.4bdc071f.js +++ b/test/output/build/npm/_import/index.4bdc071f.js @@ -1 +1 @@ -import "../_observablehq/stdlib/inputs.00000005.js"; +import "../_observablehq/stdlib/inputs.00000004.js"; diff --git a/test/output/build/duckdb/_observablehq/stdlib/inputs.00000007.css b/test/output/build/npm/_observablehq/stdlib/inputs.00000004.js similarity index 100% rename from test/output/build/duckdb/_observablehq/stdlib/inputs.00000007.css rename to test/output/build/npm/_observablehq/stdlib/inputs.00000004.js diff --git a/test/output/build/duckdb/_observablehq/theme-air,near-midnight.00000004.css b/test/output/build/npm/_observablehq/stdlib/inputs.00000005.css similarity index 100% rename from test/output/build/duckdb/_observablehq/theme-air,near-midnight.00000004.css rename to test/output/build/npm/_observablehq/stdlib/inputs.00000005.css diff --git a/test/output/build/npm/_observablehq/theme-air,near-midnight.00000004.css b/test/output/build/npm/_observablehq/theme-air,near-midnight.00000006.css similarity index 100% rename from test/output/build/npm/_observablehq/theme-air,near-midnight.00000004.css rename to test/output/build/npm/_observablehq/theme-air,near-midnight.00000006.css diff --git a/test/output/build/npm/index.html b/test/output/build/npm/index.html index 64771f980..a14a21894 100644 --- a/test/output/build/npm/index.html +++ b/test/output/build/npm/index.html @@ -6,16 +6,16 @@ - - + + - - + + - +