From a238f3bc4b6252d6431f2ac7a9fb1a79237683bf Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 16:48:30 -0400 Subject: [PATCH 01/12] =?UTF-8?q?=E2=99=BB=EF=B8=8F=20Refactor=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Moves fixtures directory to the root, uses file snapshot in unit test, and creates test helper script for pipeline tests. Updates CONTRIBUTING. --- .github/workflows/pipeline.yaml | 47 +++---------------- CONTRIBUTING.md | 13 +++-- eslint.config.js | 2 +- .../casing/camelCase.d.css.ts | 2 +- .../casing/camelCaseOnly.d.css.ts | 2 +- {src/fixtures => fixtures}/casing/casing.css | 0 .../casing/dashes.d.css.ts | 2 +- .../casing/dashesOnly.d.css.ts | 2 +- .../casing/none.d.css.ts | 2 +- {src/fixtures => fixtures}/foo.css | 0 {src/fixtures => fixtures}/foo.d.css.ts | 2 +- {src/fixtures => fixtures}/foo.module.css | 0 .../fixtures => fixtures}/foo.module.d.css.ts | 2 +- .../no-declaration-file.css | 0 package-lock.json | 8 ++-- package.json | 8 ++-- scripts/test.sh | 23 +++++++++ src/logic.test.ts | 7 +-- 18 files changed, 56 insertions(+), 66 deletions(-) rename {src/fixtures => fixtures}/casing/camelCase.d.css.ts (88%) rename {src/fixtures => fixtures}/casing/camelCaseOnly.d.css.ts (78%) rename {src/fixtures => fixtures}/casing/casing.css (100%) rename {src/fixtures => fixtures}/casing/dashes.d.css.ts (85%) rename {src/fixtures => fixtures}/casing/dashesOnly.d.css.ts (78%) rename {src/fixtures => fixtures}/casing/none.d.css.ts (82%) rename {src/fixtures => fixtures}/foo.css (100%) rename {src/fixtures => fixtures}/foo.d.css.ts (63%) rename {src/fixtures => fixtures}/foo.module.css (100%) rename {src/fixtures => fixtures}/foo.module.d.css.ts (61%) rename {src/fixtures => fixtures}/no-declaration-file.css (100%) create mode 100755 scripts/test.sh diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 62c49f2..972dc6d 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -77,58 +77,25 @@ jobs: - name: Build run: npm run build - # Run tests - # - # - Run from $RUNNER_TEMP for auto-cleanup. - # - `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). - # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. - # - Use `diff` to compare the files. - # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. - - name: "Test 1: Default case" run: | - cp src/fixtures/casing/casing.css $RUNNER_TEMP/casing.css - cp src/fixtures/casing/dashesOnly.d.css.ts $RUNNER_TEMP/expected.d.css.ts - - cd $RUNNER_TEMP - $GITHUB_WORKSPACE/dist/main.js '*.css' - diff --strip-trailing-cr -uI '//.*' expected.d.css.ts casing.d.css.ts + scripts/test.sh foo - - name: "Test 2: localsConvention, second position" + - name: "Test 2: localsConvention, first position" run: | - cp src/fixtures/casing/casing.css $RUNNER_TEMP/casing.css - cp src/fixtures/casing/camelCaseOnly.d.css.ts $RUNNER_TEMP/expected.d.css.ts - - cd $RUNNER_TEMP - $GITHUB_WORKSPACE/dist/main.js '*.css' --localsConvention camelCaseOnly - diff --strip-trailing-cr -uI '//.*' expected.d.css.ts casing.d.css.ts + scripts/test.sh casing/casing '--localsConvention camelCaseOnly' casing/camelCaseOnly - - name: "Test 3: localsConvention, first position" + - name: "Test 3: localsConvention, second position" run: | - cp src/fixtures/casing/casing.css $RUNNER_TEMP/casing.css - cp src/fixtures/casing/camelCaseOnly.d.css.ts $RUNNER_TEMP/expected.d.css.ts - - cd $RUNNER_TEMP - $GITHUB_WORKSPACE/dist/main.js --localsConvention camelCaseOnly '*.css' - diff --strip-trailing-cr -uI '//.*' expected.d.css.ts casing.d.css.ts + scripts/test.sh casing/casing '' casing/camelCaseOnly '--localsConvention camelCaseOnly' - name: "Test 4: relative outdir" run: | - cp src/fixtures/casing/casing.css $RUNNER_TEMP/casing.css - cp src/fixtures/casing/dashesOnly.d.css.ts $RUNNER_TEMP/expected.d.css.ts - - cd $RUNNER_TEMP - $GITHUB_WORKSPACE/dist/main.js '*.css' --outdir generated - diff --strip-trailing-cr -uI '//.*' expected.d.css.ts generated/casing.d.css.ts + scripts/test.sh foo '--outdir generated' '' '' generated - name: "Test 5: absolute outdir" run: | - cp src/fixtures/casing/casing.css $RUNNER_TEMP/casing.css - cp src/fixtures/casing/dashesOnly.d.css.ts $RUNNER_TEMP/expected.d.css.ts - - cd $RUNNER_TEMP - $GITHUB_WORKSPACE/dist/main.js '*.css' -o $GITHUB_WORKSPACE/generated - diff --strip-trailing-cr -uI '//.*' expected.d.css.ts $GITHUB_WORKSPACE/generated/casing.d.css.ts + scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3656338..06df752 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,6 +1,6 @@ # Contributing -The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [[RFC2119]] [[RFC8174]] when, and only when, they appear in all capitals, as shown here. +The keywords "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and "OPTIONAL" in this document are to be interpreted as described in BCP 14 [[RFC2119]] [[RFC8174]] when, and only when, they appear in all capitals, as shown here. ## Getting started @@ -20,9 +20,12 @@ The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", "SHOULD", "S The [src](./src) directory contains the main and test sources. -- [main.js](./src/main.js) represents the entry point (the CLI tool). -- [generate-declaration.js](./src/generate-declaration.js) represents the unit-tested JS logic. -- [fixtures](./src/fixtures) directory contains files for data-file-driven unit tests. +- [main.ts](./src/main.ts) represents the entry point (the CLI tool). +- [logic.ts](./src/logic.ts) represents the unit-tested logic. + +The [fixtures](fixtures) directory contains files for data-file-driven unit tests. + +The [scripts](./scripts) directory contains the esbuild build script and pipeline test helper script. ## Expectations @@ -31,7 +34,7 @@ All contributions MUST adhere to the following expectations. 1. Every change MUST have unit tests. 2. Every change MUST have a GitHub issue linked. 3. Any configuration option change SHOULD be discussed in a GitHub issue first. -4. The PR build (see [pipeline.yaml](./.github/workflows/pipeline.yaml)) MUST succeed. +4. The PR build and test (see [pipeline.yaml](./.github/workflows/pipeline.yaml)) MUST succeed. 5. I will squash-merge the changeset into `main` upon approval. [RFC2119]: https://www.rfc-editor.org/rfc/rfc2119 diff --git a/eslint.config.js b/eslint.config.js index d291fbc..5c9aa5d 100644 --- a/eslint.config.js +++ b/eslint.config.js @@ -4,6 +4,6 @@ export default [ ...connorjsConfig, { // Ignore declaration files used for tests. These represent generated files. - ignores: [`src/fixtures/**/*.d.css.ts`], + ignores: [`fixtures/**/*.d.css.ts`], }, ]; diff --git a/src/fixtures/casing/camelCase.d.css.ts b/fixtures/casing/camelCase.d.css.ts similarity index 88% rename from src/fixtures/casing/camelCase.d.css.ts rename to fixtures/casing/camelCase.d.css.ts index 7c003cd..f5cc596 100644 --- a/src/fixtures/casing/camelCase.d.css.ts +++ b/fixtures/casing/camelCase.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/casing/casing.css` by css-typed at $TIME +// Generated from `fixtures/casing/casing.css` by css-typed at $TIME const lowercase: string; const UPPERCASE: string; diff --git a/src/fixtures/casing/camelCaseOnly.d.css.ts b/fixtures/casing/camelCaseOnly.d.css.ts similarity index 78% rename from src/fixtures/casing/camelCaseOnly.d.css.ts rename to fixtures/casing/camelCaseOnly.d.css.ts index 64319e4..d75f79d 100644 --- a/src/fixtures/casing/camelCaseOnly.d.css.ts +++ b/fixtures/casing/camelCaseOnly.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/casing/casing.css` by css-typed at $TIME +// Generated from `fixtures/casing/casing.css` by css-typed at $TIME export const lowercase: string; export const uppercase: string; diff --git a/src/fixtures/casing/casing.css b/fixtures/casing/casing.css similarity index 100% rename from src/fixtures/casing/casing.css rename to fixtures/casing/casing.css diff --git a/src/fixtures/casing/dashes.d.css.ts b/fixtures/casing/dashes.d.css.ts similarity index 85% rename from src/fixtures/casing/dashes.d.css.ts rename to fixtures/casing/dashes.d.css.ts index df6d7e5..22cde24 100644 --- a/src/fixtures/casing/dashes.d.css.ts +++ b/fixtures/casing/dashes.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/casing/casing.css` by css-typed at $TIME +// Generated from `fixtures/casing/casing.css` by css-typed at $TIME const lowercase: string; const UPPERCASE: string; diff --git a/src/fixtures/casing/dashesOnly.d.css.ts b/fixtures/casing/dashesOnly.d.css.ts similarity index 78% rename from src/fixtures/casing/dashesOnly.d.css.ts rename to fixtures/casing/dashesOnly.d.css.ts index 20ac081..423956b 100644 --- a/src/fixtures/casing/dashesOnly.d.css.ts +++ b/fixtures/casing/dashesOnly.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/casing/casing.css` by css-typed at $TIME +// Generated from `fixtures/casing/casing.css` by css-typed at $TIME export const lowercase: string; export const UPPERCASE: string; diff --git a/src/fixtures/casing/none.d.css.ts b/fixtures/casing/none.d.css.ts similarity index 82% rename from src/fixtures/casing/none.d.css.ts rename to fixtures/casing/none.d.css.ts index 0575758..60ac1e9 100644 --- a/src/fixtures/casing/none.d.css.ts +++ b/fixtures/casing/none.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/casing/casing.css` by css-typed at $TIME +// Generated from `fixtures/casing/casing.css` by css-typed at $TIME const lowercase: string; const UPPERCASE: string; diff --git a/src/fixtures/foo.css b/fixtures/foo.css similarity index 100% rename from src/fixtures/foo.css rename to fixtures/foo.css diff --git a/src/fixtures/foo.d.css.ts b/fixtures/foo.d.css.ts similarity index 63% rename from src/fixtures/foo.d.css.ts rename to fixtures/foo.d.css.ts index b9a41fc..6d879f4 100644 --- a/src/fixtures/foo.d.css.ts +++ b/fixtures/foo.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/foo.css` by css-typed at $TIME +// Generated from `fixtures/foo.css` by css-typed at $TIME export const foo: string; export const bar: string; diff --git a/src/fixtures/foo.module.css b/fixtures/foo.module.css similarity index 100% rename from src/fixtures/foo.module.css rename to fixtures/foo.module.css diff --git a/src/fixtures/foo.module.d.css.ts b/fixtures/foo.module.d.css.ts similarity index 61% rename from src/fixtures/foo.module.d.css.ts rename to fixtures/foo.module.d.css.ts index a3398ee..16ee154 100644 --- a/src/fixtures/foo.module.d.css.ts +++ b/fixtures/foo.module.d.css.ts @@ -1,4 +1,4 @@ -// Generated from `src/fixtures/foo.module.css` by css-typed at $TIME +// Generated from `fixtures/foo.module.css` by css-typed at $TIME export const foo: string; export const bar: string; diff --git a/src/fixtures/no-declaration-file.css b/fixtures/no-declaration-file.css similarity index 100% rename from src/fixtures/no-declaration-file.css rename to fixtures/no-declaration-file.css diff --git a/package-lock.json b/package-lock.json index dba8318..24fb7e6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,7 +24,7 @@ "@types/lodash.camelcase": "^4.3.9", "@types/node": "^20.14.14", "esbuild": "~0.23.0", - "eslint-config-connorjs": "^1.0.0", + "eslint-config-connorjs": "^1.1.0", "husky": "^9.1.4", "is-ci": "^3.0.1", "lint-staged": "^15.2.8", @@ -2552,9 +2552,9 @@ } }, "node_modules/eslint-config-connorjs": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/eslint-config-connorjs/-/eslint-config-connorjs-1.0.0.tgz", - "integrity": "sha512-KLdWBsS0udknT/Yqo7nJjwkVDYFsZgPPVkJupwLJMTDl8P8Oa27z502cHgl6N2/HPV6x/UYxC7Z20p8m09/Gow==", + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/eslint-config-connorjs/-/eslint-config-connorjs-1.1.0.tgz", + "integrity": "sha512-mQFdBDe/8q0bCI3HBaVvf1sm/Sk6yT9owoZxx8O1dguDVGwtBH3yykMpckBLYbU/6jz5zvr9r/V0RA+4z++wXw==", "dev": true, "dependencies": { "@eslint/js": "^8.57.0", diff --git a/package.json b/package.json index 33e2160..0722196 100644 --- a/package.json +++ b/package.json @@ -26,12 +26,14 @@ "engines": { "node": ">=18" }, + "engineStrict": true, "bin": { "css-typed": "dist/main.js" }, "files": [ "dist" ], + "main": "dist/main.js", "scripts": { "build": "node scripts/build.js", "ci-build": "npm-run-all -l -p eslint prettier test tsc -s build", @@ -43,7 +45,6 @@ "test": "vitest run", "tsc": "tsc" }, - "engineStrict": true, "dependencies": { "@commander-js/extra-typings": "^12.1.0", "commander": "^12.1.0", @@ -57,7 +58,7 @@ "@types/lodash.camelcase": "^4.3.9", "@types/node": "^20.14.14", "esbuild": "~0.23.0", - "eslint-config-connorjs": "^1.0.0", + "eslint-config-connorjs": "^1.1.0", "husky": "^9.1.4", "is-ci": "^3.0.1", "lint-staged": "^15.2.8", @@ -65,6 +66,5 @@ "prettier": "^3.3.3", "typescript": "^5.5.4", "vitest": "^2.0.5" - }, - "main": "dist/main.js" + } } diff --git a/scripts/test.sh b/scripts/test.sh new file mode 100755 index 0000000..639b3aa --- /dev/null +++ b/scripts/test.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash +set -euo pipefail +IFS=$'\n\t' + +# $1 is the input name, relative to `fixtures`. Required. +# $2 is the standard (before) options. Defaults to "". +# $3 is the output name, relative to `fixtures`. Defaults to $1. +# $4 is the after options. Defaults to "". +# $5 is the path prefix for output. Defaults to "". + +# Run from $RUNNER_TEMP for auto-cleanup. +cp fixtures/"$1".css "$RUNNER_TEMP"/test.css +cp fixtures/"${3:-$1}".d.css.ts "$RUNNER_TEMP"/expected.d.css.ts +pushd "$RUNNER_TEMP" > /dev/null || exit + +# `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). +# But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. +# shellcheck disable=SC2086 +"$GITHUB_WORKSPACE"/dist/main.js ${2:-} '*.css' ${4:-} + +# Use `diff` to compare the files. +# Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. +diff --color=auto --strip-trailing-cr -uI '//.*' expected.d.css.ts "${5:-}"test.d.css.ts diff --git a/src/logic.test.ts b/src/logic.test.ts index 9737a02..be1ab81 100644 --- a/src/logic.test.ts +++ b/src/logic.test.ts @@ -1,4 +1,3 @@ -import { readFileSync } from "node:fs"; import path from "node:path"; import * as process from "node:process"; @@ -31,10 +30,8 @@ describe(`css-typed`, () => { const inputPath = fixtureFile(inputFilename); const outputPath = fixtureFile(outputFilename); - const expected = readFileSync(outputPath, { encoding: `utf8` }); - const generated = await generateDeclaration(inputPath, `$TIME`, options); - expect(generated).toStrictEqual(expected); + await expect(generated).toMatchFileSnapshot(outputPath); }); }); @@ -57,5 +54,5 @@ describe(`css-typed`, () => { }); function fixtureFile(filename: string) { - return path.join(import.meta.dirname, `fixtures`, filename); + return path.join(import.meta.dirname, `..`, `fixtures`, filename); } From 6fb37d53ae54c8437578b1279651cb677abe7ea9 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:03:03 -0400 Subject: [PATCH 02/12] switch to eval for test.sh --- scripts/test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 639b3aa..87fbcd1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -15,8 +15,8 @@ pushd "$RUNNER_TEMP" > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -# shellcheck disable=SC2086 -"$GITHUB_WORKSPACE"/dist/main.js ${2:-} '*.css' ${4:-} +echo "css-typed ${2:-} '*.css' ${4:-}" +eval "$GITHUB_WORKSPACE/dist/main.js ${2:-} '*.css' ${4:-}" # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. From ce12d09c1d4c66432a80f869698086edc52cdf50 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:07:09 -0400 Subject: [PATCH 03/12] Fix test case --- .github/workflows/pipeline.yaml | 4 ++-- scripts/test.sh | 5 +++-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 972dc6d..8390d3f 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -91,11 +91,11 @@ jobs: - name: "Test 4: relative outdir" run: | - scripts/test.sh foo '--outdir generated' '' '' generated + scripts/test.sh foo '--outdir generated' '' '' generated/ - name: "Test 5: absolute outdir" run: | - scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated + scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/scripts/test.sh b/scripts/test.sh index 87fbcd1..3613bce 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -15,8 +15,9 @@ pushd "$RUNNER_TEMP" > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -echo "css-typed ${2:-} '*.css' ${4:-}" -eval "$GITHUB_WORKSPACE/dist/main.js ${2:-} '*.css' ${4:-}" +args="${2:-} '*.css' ${4:-}" +echo "css-typed $args" +eval "$GITHUB_WORKSPACE/dist/main.js $args" # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. From cd0f242a516fc49494d7594f9fa71525b5b7abc9 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:09:13 -0400 Subject: [PATCH 04/12] Fix windows --- scripts/test.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/scripts/test.sh b/scripts/test.sh index 3613bce..7ef1cfd 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -15,7 +15,7 @@ pushd "$RUNNER_TEMP" > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -args="${2:-} '*.css' ${4:-}" +args="${2:-} \"*.css\" ${4:-}" echo "css-typed $args" eval "$GITHUB_WORKSPACE/dist/main.js $args" From f5b70a85f971cd9104165d7dfddf041593f115f7 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:15:15 -0400 Subject: [PATCH 05/12] Trying to fix windows... --- scripts/test.sh | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 7ef1cfd..a98a90d 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -9,15 +9,14 @@ IFS=$'\n\t' # $5 is the path prefix for output. Defaults to "". # Run from $RUNNER_TEMP for auto-cleanup. -cp fixtures/"$1".css "$RUNNER_TEMP"/test.css -cp fixtures/"${3:-$1}".d.css.ts "$RUNNER_TEMP"/expected.d.css.ts -pushd "$RUNNER_TEMP" > /dev/null || exit +cp fixtures/$1.css $RUNNER_TEMP/test.css +cp fixtures/${3:-$1}.d.css.ts $RUNNER_TEMP/expected.d.css.ts +pushd $RUNNER_TEMP > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -args="${2:-} \"*.css\" ${4:-}" -echo "css-typed $args" -eval "$GITHUB_WORKSPACE/dist/main.js $args" +echo "css-typed ${2:-} \"*.css\" ${4:-}" +$GITHUB_WORKSPACE/dist/main.js ${2:-} "*.css" ${4:-} # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. From 729a3f931b731866f3d1fcb1fd842818df8168ff Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:28:31 -0400 Subject: [PATCH 06/12] try arrays --- .github/workflows/pipeline.yaml | 12 ++++++++---- scripts/test.sh | 26 +++++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 8390d3f..b99f762 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -83,19 +83,23 @@ jobs: - name: "Test 2: localsConvention, first position" run: | - scripts/test.sh casing/casing '--localsConvention camelCaseOnly' casing/camelCaseOnly + opts=(--localsConvention camelCaseOnly) + scripts/test.sh casing/casing "opts[@]" casing/camelCaseOnly - name: "Test 3: localsConvention, second position" run: | - scripts/test.sh casing/casing '' casing/camelCaseOnly '--localsConvention camelCaseOnly' + opts=(--localsConvention camelCaseOnly) + scripts/test.sh casing/casing '' casing/camelCaseOnly "opts[@]" - name: "Test 4: relative outdir" run: | - scripts/test.sh foo '--outdir generated' '' '' generated/ + opts=(--outdir generated) + scripts/test.sh foo "opts[@]" '' '' generated/ - name: "Test 5: absolute outdir" run: | - scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated/ + opts=(-o $GITHUB_WORKSPACE/generated) + scripts/test.sh foo "opts[@]" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/scripts/test.sh b/scripts/test.sh index a98a90d..4087468 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,23 +1,31 @@ #!/usr/bin/env bash -set -euo pipefail -IFS=$'\n\t' # $1 is the input name, relative to `fixtures`. Required. -# $2 is the standard (before) options. Defaults to "". +input=$1 + +# $2 is the standard (before) options. Use an array. Defaults to (). +beforeOpts=${2:-()} + # $3 is the output name, relative to `fixtures`. Defaults to $1. -# $4 is the after options. Defaults to "". +output=$2 + +# $4 is the after options. Use an array. Defaults to (). +afterOpts=${4:-()} + # $5 is the path prefix for output. Defaults to "". +prefix=${5:-} # Run from $RUNNER_TEMP for auto-cleanup. -cp fixtures/$1.css $RUNNER_TEMP/test.css -cp fixtures/${3:-$1}.d.css.ts $RUNNER_TEMP/expected.d.css.ts +cp fixtures/${input}.css $RUNNER_TEMP/test.css +cp fixtures/${output}.d.css.ts $RUNNER_TEMP/expected.d.css.ts pushd $RUNNER_TEMP > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -echo "css-typed ${2:-} \"*.css\" ${4:-}" -$GITHUB_WORKSPACE/dist/main.js ${2:-} "*.css" ${4:-} +echo "css-typed ${beforeOpts} \"*.css\" ${afterOpts}" +# shellcheck disable=SC2068 +$GITHUB_WORKSPACE/dist/main.js ${beforeOpts[@]} \"*.css\" ${afterOpts[@]} # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. -diff --color=auto --strip-trailing-cr -uI '//.*' expected.d.css.ts "${5:-}"test.d.css.ts +diff --color=auto --strip-trailing-cr -uI '//.*' expected.d.css.ts ${prefix}test.d.css.ts From bc1210a09e2d4c99239bde26e7b4c6d3047663ac Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:32:53 -0400 Subject: [PATCH 07/12] debugging --- scripts/test.sh | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/test.sh b/scripts/test.sh index 4087468..33e7be1 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,16 +1,17 @@ #!/usr/bin/env bash +set -x # $1 is the input name, relative to `fixtures`. Required. input=$1 # $2 is the standard (before) options. Use an array. Defaults to (). -beforeOpts=${2:-()} +beforeOpts=${2:-} # $3 is the output name, relative to `fixtures`. Defaults to $1. -output=$2 +output=${3:-$1} # $4 is the after options. Use an array. Defaults to (). -afterOpts=${4:-()} +afterOpts=${4:-} # $5 is the path prefix for output. Defaults to "". prefix=${5:-} @@ -24,7 +25,7 @@ pushd $RUNNER_TEMP > /dev/null || exit # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. echo "css-typed ${beforeOpts} \"*.css\" ${afterOpts}" # shellcheck disable=SC2068 -$GITHUB_WORKSPACE/dist/main.js ${beforeOpts[@]} \"*.css\" ${afterOpts[@]} +$GITHUB_WORKSPACE/dist/main.js ${beforeOpts[@]} "*.css" ${afterOpts[@]} # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. From 3059d90cfe89c72e15cd4d99345956b8a1844d8f Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:35:29 -0400 Subject: [PATCH 08/12] =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D?= =?UTF-8?q?=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pipeline.yaml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index b99f762..4ef20a8 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -84,12 +84,12 @@ jobs: - name: "Test 2: localsConvention, first position" run: | opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing "opts[@]" casing/camelCaseOnly + scripts/test.sh casing/casing "$opts[@]" casing/camelCaseOnly - name: "Test 3: localsConvention, second position" run: | opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing '' casing/camelCaseOnly "opts[@]" + scripts/test.sh casing/casing '' casing/camelCaseOnly "$opts[@]" - name: "Test 4: relative outdir" run: | @@ -99,7 +99,7 @@ jobs: - name: "Test 5: absolute outdir" run: | opts=(-o $GITHUB_WORKSPACE/generated) - scripts/test.sh foo "opts[@]" '' '' "$GITHUB_WORKSPACE"/generated/ + scripts/test.sh foo "$opts[@]" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} From d59620183778605c1a67d06cda3debdf023caa16 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:37:58 -0400 Subject: [PATCH 09/12] =?UTF-8?q?=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D?= =?UTF-8?q?=E2=99=82=F0=9F=A4=A6=F0=9F=8F=BB=E2=80=8D=E2=99=82=EF=B8=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/pipeline.yaml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 4ef20a8..85a494c 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -84,22 +84,22 @@ jobs: - name: "Test 2: localsConvention, first position" run: | opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing "$opts[@]" casing/camelCaseOnly + scripts/test.sh casing/casing "${opts[@]}" casing/camelCaseOnly - name: "Test 3: localsConvention, second position" run: | opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing '' casing/camelCaseOnly "$opts[@]" + scripts/test.sh casing/casing '' casing/camelCaseOnly "${opts[@]}" - name: "Test 4: relative outdir" run: | opts=(--outdir generated) - scripts/test.sh foo "opts[@]" '' '' generated/ + scripts/test.sh foo "${opts[@]}" '' '' generated/ - name: "Test 5: absolute outdir" run: | opts=(-o $GITHUB_WORKSPACE/generated) - scripts/test.sh foo "$opts[@]" '' '' "$GITHUB_WORKSPACE"/generated/ + scripts/test.sh foo "${opts[@]}" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} From f2605284f821e44f9354504c7be65f399af04903 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:44:28 -0400 Subject: [PATCH 10/12] try read --- .github/workflows/pipeline.yaml | 29 ++++++++++++++++------------- scripts/test.sh | 10 +++++----- 2 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index 85a494c..d4c75ea 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -54,10 +54,10 @@ jobs: matrix: node: - 20.x - - 22.x + #- 22.x platform: - os: ubuntu-latest - - os: macos-latest + #- os: macos-latest - os: windows-latest fail-fast: false @@ -82,24 +82,27 @@ jobs: scripts/test.sh foo - name: "Test 2: localsConvention, first position" + if: success() || failure() run: | - opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing "${opts[@]}" casing/camelCaseOnly + scripts/test.sh casing/casing "--localsConvention camelCaseOnly" casing/camelCaseOnly - name: "Test 3: localsConvention, second position" + if: success() || failure() run: | opts=(--localsConvention camelCaseOnly) scripts/test.sh casing/casing '' casing/camelCaseOnly "${opts[@]}" - - name: "Test 4: relative outdir" - run: | - opts=(--outdir generated) - scripts/test.sh foo "${opts[@]}" '' '' generated/ - - - name: "Test 5: absolute outdir" - run: | - opts=(-o $GITHUB_WORKSPACE/generated) - scripts/test.sh foo "${opts[@]}" '' '' "$GITHUB_WORKSPACE"/generated/ + # - name: "Test 4: relative outdir" + # if: success() || failure() + # run: | + # opts=(--outdir generated) + # scripts/test.sh foo "${opts[@]}" '' '' generated/ + # + # - name: "Test 5: absolute outdir" + # if: success() || failure() + # run: | + # opts=(-o $GITHUB_WORKSPACE/generated) + # scripts/test.sh foo "${opts[@]}" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/scripts/test.sh b/scripts/test.sh index 33e7be1..01b8ce7 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,14 +4,14 @@ set -x # $1 is the input name, relative to `fixtures`. Required. input=$1 -# $2 is the standard (before) options. Use an array. Defaults to (). -beforeOpts=${2:-} +# $2 is the standard (before) options. Defaults to "". +IFS=" " read -r -a beforeOpts <<< "${2:-}" # $3 is the output name, relative to `fixtures`. Defaults to $1. output=${3:-$1} -# $4 is the after options. Use an array. Defaults to (). -afterOpts=${4:-} +# $4 is the after options. Use an array. Defaults to "". +IFS=" " read -r -a afterOpts <<< "${4:-}" # $5 is the path prefix for output. Defaults to "". prefix=${5:-} @@ -23,7 +23,7 @@ pushd $RUNNER_TEMP > /dev/null || exit # `./dist/main.js` is executing local `css-typed` as if installed (same as `bin`). # But it is `$GITHUB_WORKSPACE/dist/main.js` b/c we `cd $RUNNER_TEMP`. -echo "css-typed ${beforeOpts} \"*.css\" ${afterOpts}" +echo "css-typed ${beforeOpts[*]} \"*.css\" ${afterOpts[*]}" # shellcheck disable=SC2068 $GITHUB_WORKSPACE/dist/main.js ${beforeOpts[@]} "*.css" ${afterOpts[@]} From f2016f01277baafa647de239769363e0ac71f08c Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:50:12 -0400 Subject: [PATCH 11/12] that worked... expand --- .github/workflows/pipeline.yaml | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index d4c75ea..db9102e 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -89,20 +89,17 @@ jobs: - name: "Test 3: localsConvention, second position" if: success() || failure() run: | - opts=(--localsConvention camelCaseOnly) - scripts/test.sh casing/casing '' casing/camelCaseOnly "${opts[@]}" - - # - name: "Test 4: relative outdir" - # if: success() || failure() - # run: | - # opts=(--outdir generated) - # scripts/test.sh foo "${opts[@]}" '' '' generated/ - # - # - name: "Test 5: absolute outdir" - # if: success() || failure() - # run: | - # opts=(-o $GITHUB_WORKSPACE/generated) - # scripts/test.sh foo "${opts[@]}" '' '' "$GITHUB_WORKSPACE"/generated/ + scripts/test.sh casing/casing '' casing/camelCaseOnly "--localsConvention camelCaseOnly" + + - name: "Test 4: relative outdir" + if: success() || failure() + run: | + scripts/test.sh foo "--outdir generated" '' '' generated/ + + - name: "Test 5: absolute outdir" + if: success() || failure() + run: | + scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} From 9b9f4057177b7da97483ccf3d9607c36c10a9313 Mon Sep 17 00:00:00 2001 From: Connor Sullivan Date: Sat, 3 Aug 2024 17:52:30 -0400 Subject: [PATCH 12/12] prep for merge --- .github/workflows/pipeline.yaml | 10 +++++----- scripts/test.sh | 3 +-- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/.github/workflows/pipeline.yaml b/.github/workflows/pipeline.yaml index db9102e..f1c78d7 100644 --- a/.github/workflows/pipeline.yaml +++ b/.github/workflows/pipeline.yaml @@ -54,10 +54,10 @@ jobs: matrix: node: - 20.x - #- 22.x + - 22.x platform: - os: ubuntu-latest - #- os: macos-latest + - os: macos-latest - os: windows-latest fail-fast: false @@ -89,17 +89,17 @@ jobs: - name: "Test 3: localsConvention, second position" if: success() || failure() run: | - scripts/test.sh casing/casing '' casing/camelCaseOnly "--localsConvention camelCaseOnly" + scripts/test.sh casing/casing "" casing/camelCaseOnly "--localsConvention camelCaseOnly" - name: "Test 4: relative outdir" if: success() || failure() run: | - scripts/test.sh foo "--outdir generated" '' '' generated/ + scripts/test.sh foo "--outdir generated" "" "" generated/ - name: "Test 5: absolute outdir" if: success() || failure() run: | - scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" '' '' "$GITHUB_WORKSPACE"/generated/ + scripts/test.sh foo "-o $GITHUB_WORKSPACE/generated" "" "" "$GITHUB_WORKSPACE"/generated/ Publish: if: ${{ github.ref == 'refs/heads/main' }} diff --git a/scripts/test.sh b/scripts/test.sh index 01b8ce7..8d7e62e 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -1,5 +1,4 @@ #!/usr/bin/env bash -set -x # $1 is the input name, relative to `fixtures`. Required. input=$1 @@ -29,4 +28,4 @@ $GITHUB_WORKSPACE/dist/main.js ${beforeOpts[@]} "*.css" ${afterOpts[@]} # Use `diff` to compare the files. # Use `-I '//.*'` to ignore the first line (comment) which has generated path and timestamp. -diff --color=auto --strip-trailing-cr -uI '//.*' expected.d.css.ts ${prefix}test.d.css.ts +diff --color=auto --strip-trailing-cr -uI "//.*" expected.d.css.ts ${prefix}test.d.css.ts