Skip to content
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
14 changes: 12 additions & 2 deletions packages/postcss-tape/src/format-asserts.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import type { Warning } from 'postcss';

export const dashesSeparator = '----------------------------------------';

export function formatCSSAssertError(testCaseLabel, testCaseOptions, err, forGithubAnnotation = false) {
Expand Down Expand Up @@ -25,7 +27,7 @@ export function formatCSSAssertError(testCaseLabel, testCaseOptions, err, forGit
return formatted;
}

export function formatWarningsAssertError(testCaseLabel, testCaseOptions, actual, expected, forGithubAnnotation = false) {
export function formatWarningsAssertError(testCaseLabel, testCaseOptions, actual: Array<Warning>, expected: number, forGithubAnnotation = false) {
let formatted = '';
formatted += `\n${testCaseLabel}\n\n`;

Expand All @@ -41,9 +43,17 @@ export function formatWarningsAssertError(testCaseLabel, testCaseOptions, actual
}
}

formatted += `unexpected or missing warnings :\n+ actual ${actual}\n- expected ${expected}\n`;
formatted += `unexpected or missing warnings :\n+ actual ${actual.length}\n- expected ${expected}\n`;

if (!forGithubAnnotation) {
actual.forEach((warning) => {
formatted += `\n[${warning.plugin}]: ${warning.text}`;
});

if (actual.length) {
formatted += '\n';
}

formatted += '\n' + dashesSeparator;
}

Expand Down
11 changes: 8 additions & 3 deletions packages/postcss-tape/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,11 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
const resultString = result.css.toString();
await fsp.writeFile(resultFilePath, resultString, 'utf8');

// Allow contributors to rewrite `.expect.css` files through postcss-tape.
if (process.env.REWRITE_EXPECTS) {
fsp.writeFile(expectFilePath, resultString, 'utf8');
}

// Can't do further checks if "expect" is missing.
if (expected === false) {
continue;
Expand Down Expand Up @@ -352,18 +357,18 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
if (result.warnings().length || testCaseOptions.warnings) {
assert.strictEqual(result.warnings().length, testCaseOptions.warnings);
}
} catch (err) {
} catch (_) {
hasErrors = true;

if (emitGitHubAnnotations) {
console.log(formatGitHubActionAnnotation(
formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings().length, testCaseOptions.warnings, true),
formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings(), testCaseOptions.warnings, true),
'error',
{ file: normalizeFilePathForGithubAnnotation(expectFilePath), line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings().length, testCaseOptions.warnings));
console.error(formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings(), testCaseOptions.warnings));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ unexpected or missing warnings :
+ actual 1
- expected 0

[a-plugin]: a warning

----------------------------------------

basic:with-multiple-warnings
Expand All @@ -30,6 +32,10 @@ unexpected or missing warnings :
+ actual 3
- expected 7

[a-plugin]: a warning
[a-plugin]: a warning
[a-plugin]: a warning

----------------------------------------

unexpected failures:
Expand Down
1 change: 1 addition & 0 deletions plugin-packs/postcss-preset-env/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions plugins/css-blank-pseudo/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"cli": "css-blank-pseudo",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-base-plugin/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:cli": "bash ./test/cli/test.sh",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-custom-properties/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && node .tape.cjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-hwb-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-image-set-function/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"engines": {
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-nesting/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:deno": "deno run --unstable --allow-env --allow-read test/deno/test.js",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
Expand Down
1 change: 1 addition & 0 deletions plugins/postcss-pseudo-class-any-link/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"prepublishOnly": "npm run clean && npm run build && npm run test",
"stryker": "stryker run --logLevel error",
"test": "node .tape.mjs && npm run test:exports",
"test:rewrite-expects": "REWRITE_EXPECTS=true node .tape.mjs",
"test:exports": "node ./test/_import.mjs && node ./test/_require.cjs"
},
"engines": {
Expand Down