Skip to content

Enable full CI for CLI #17

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
Nov 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ jobs:
# - run: npm run build --workspaces --if-present

- run: |
npm run build --workspace="@csstools/base-cli"
npm run build --workspace="@csstools/base-cli" --workspace="@csstools/postcss-base-plugin"
# running install places the cli in node_modules/bin
npm install
npm run test --workspace="@csstools/base-cli"
# npm run build --workspace="@csstools/base-cli" --workspace="@csstools/postcss-base-plugin"
# npm run test --workspace="@csstools/base-cli" --workspace="@csstools/postcss-base-plugin"
npm run test:cli --workspace="@csstools/postcss-base-plugin"
2 changes: 1 addition & 1 deletion packages/base-cli/src/io-fs-to-fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fsp from 'fs/promises';
import { promises as fsp } from 'fs';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I often just do this

Suggested change
import { promises as fsp } from 'fs';
import fs from 'fs/promises';

But feel free to leave it like this if you want to be specific

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I mostly use the specific naming. This is more a reminder for myself that I imported the promises API further down in the code. :)

import path from 'path';
import { Arguments } from './args';
import postcss, { Plugin } from 'postcss';
Expand Down
2 changes: 1 addition & 1 deletion packages/base-cli/src/io-fs-to-stdout.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fsp from 'fs/promises';
import { promises as fsp } from 'fs';
import { Arguments } from './args';
import postcss, { Plugin } from 'postcss';

Expand Down
2 changes: 1 addition & 1 deletion packages/base-cli/src/io-stdin-to-fs.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import fsp from 'fs/promises';
import { promises as fsp } from 'fs';
import path from 'path';
import { Arguments } from './args';
import postcss, { Plugin } from 'postcss';
Expand Down
3 changes: 2 additions & 1 deletion plugins/postcss-base-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"scripts": {
"prepublishOnly": "npm run build --if-present && npm run test --if-present",
"lint": "eslint src/**/*.ts",
"test": "postcss-tape && bash ./test/cli/test.sh",
"test": "postcss-tape",
"test:cli": "bash ./test/cli/test.sh",
"build": "rollup -c ../../rollup/default.ts.js",
"stryker": "stryker run --logLevel error"
},
Expand Down
2 changes: 1 addition & 1 deletion plugins/postcss-base-plugin/src/cli.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import plugin from '@csstools/postcss-base-plugin';
import plugin from './index';
import { cli, helpTextLogger } from '@csstools/base-cli';

cli(
Expand Down
47 changes: 40 additions & 7 deletions plugins/postcss-base-plugin/test/cli/test.sh
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
set -e

echo $OSTYPE

# Zero out result file
echo '' > ./test/cli/basic.result.css;

# Test with long flag
postcss-base-plugin ./test/cli/basic.css --output ./test/cli/basic.result.css

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/basic.expect.css ./test/cli/basic.result.css
if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice one

echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/basic.expect.css ./test/cli/basic.result.css
fi

# Reset result file
cat ./test/cli/basic.css > ./test/cli/basic.replace.css;
Expand All @@ -16,7 +23,12 @@ cat ./test/cli/basic.css > ./test/cli/basic.replace.css;
postcss-base-plugin ./test/cli/basic.replace.css -r

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/basic.replace.css ./test/cli/basic.replace.expect.css
if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/basic.replace.css ./test/cli/basic.replace.expect.css
fi

# Zero out result file
echo '' > ./test/cli/basic.color.result.css;
Expand All @@ -25,7 +37,12 @@ echo '' > ./test/cli/basic.color.result.css;
postcss-base-plugin ./test/cli/basic.css -o ./test/cli/basic.color.result.css -p '{ "color": "purple" }'

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/basic.color.expect.css ./test/cli/basic.color.result.css
if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/basic.color.expect.css ./test/cli/basic.color.result.css
fi

# Zero out result file
echo '' > ./test/cli/basic.stdin.result.css;
Expand All @@ -34,7 +51,12 @@ echo '' > ./test/cli/basic.stdin.result.css;
cat ./test/cli/basic.css | postcss-base-plugin > ./test/cli/basic.stdin.result.css

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/basic.stdin.expect.css ./test/cli/basic.stdin.result.css
if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/basic.stdin.expect.css ./test/cli/basic.stdin.result.css
fi

# Zero out result file
echo '' > ./test/cli/basic.no-map.result.css;
Expand All @@ -54,7 +76,12 @@ cat ./test/cli/basic.css | postcss-base-plugin --map -o ./test/cli/basic.extern

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/basic.external-map.expect.css ./test/cli/basic.external-map.result.css
git --no-pager diff --no-index --word-diff ./test/cli/basic.external-map.expect.css.map ./test/cli/basic.external-map.result.css.map
if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/basic.external-map.expect.css.map ./test/cli/basic.external-map.result.css.map
fi

# Zero out result file
echo '' > ./test/cli/out/a.css
Expand All @@ -67,9 +94,15 @@ postcss-base-plugin ./test/cli/src/a.css ./test/cli/src/b.css -m -d ./test/cli/o

# Check result
git --no-pager diff --no-index --word-diff ./test/cli/out/a.css ./test/cli/out/a.expect.css
git --no-pager diff --no-index --word-diff ./test/cli/out/a.css.map ./test/cli/out/a.expect.css.map
git --no-pager diff --no-index --word-diff ./test/cli/out/b.css ./test/cli/out/b.expect.css
git --no-pager diff --no-index --word-diff ./test/cli/out/b.css.map ./test/cli/out/b.expect.css.map

if [[ "$OSTYPE" == "msys" ]]; then
# CRLF on Windows makes it hard to test with base64 encoded sourcemaps
echo 'did not compare actual output assuming exit 0 means everything is ok'
else
git --no-pager diff --no-index --word-diff ./test/cli/out/a.css.map ./test/cli/out/a.expect.css.map
git --no-pager diff --no-index --word-diff ./test/cli/out/b.css.map ./test/cli/out/b.expect.css.map
fi

# Zero out result file
echo '' > ./test/cli/out/concatenated.css
Expand Down
4 changes: 2 additions & 2 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"compilerOptions": {
"moduleResolution": "node",
"allowJs": false,
"target": "es6",
"lib": ["es6"],
"target": "es2020",
"lib": ["es2020"],
"allowSyntheticDefaultImports": true,
"module": "es6",
"declaration": true
Expand Down