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
1 change: 1 addition & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"common-tools":
- packages/base-cli/**
- packages/postcss-tape/**
- plugins/postcss-base-plugin/**
- rollup/**

Expand Down
8 changes: 1 addition & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions packages/postcss-tape/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {

// Test cases
return async (options: Record<string, TestCaseOptions>) => {
const failureSummary = new Set();

for (const testCaseLabel in options) {
const testCaseOptions = options[testCaseLabel];

Expand Down Expand Up @@ -172,12 +174,14 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: testFilePath, line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(`\n${testCaseLabel}\n\nmissing or broken "expect" file: "${path.parse(expectFilePath).base}"\n\n${dashesSeparator}`);
}
}

let result: Result;

let sawException = false;
try {
result = await postcss(plugins).process(input, {
from: testFilePath,
Expand All @@ -188,6 +192,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
},
});
} catch (err) {
sawException = true;
if (testCaseOptions.exception && testCaseOptions.exception.test(err.message)) {
// expected an exception and got one.
continue;
Expand All @@ -197,6 +202,21 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
throw err;
}

if (!sawException && testCaseOptions.exception) {
hasErrors = true;

if (emitGitHubAnnotations) {
console.log(formatGitHubActionAnnotation(
`${testCaseLabel}\n\nexpected an exception but got none`,
'error',
{ file: testFilePath, line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(`\n${testCaseLabel}\n\nexpected an exception but got none\n\n${dashesSeparator}`);
}
}

// Try to write the result file, even if further checks fails.
// This helps writing new tests for plugins.
// Taking the result file as a starting point for the expect file.
Expand Down Expand Up @@ -225,6 +245,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: normalizeFilePathForGithubAnnotation(expectFilePath), line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(formatCSSAssertError(testCaseLabel, testCaseOptions, err));
}
}
Expand All @@ -246,6 +267,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: testFilePath, line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(`\n${testCaseLabel}\n\nbroken source map: ${JSON.stringify(result.map.toJSON().sources)}\n\n${dashesSeparator}`);
}
}
Expand Down Expand Up @@ -282,6 +304,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: expectFilePath, line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(`\n${testCaseLabel}\n\nresult was not parsable with PostCSS.\n\n${dashesSeparator}`);
}
}
Expand Down Expand Up @@ -317,6 +340,7 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: normalizeFilePathForGithubAnnotation(expectFilePath), line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error('testing older PostCSS:\n' + formatCSSAssertError(testCaseLabel, testCaseOptions, err));
}
}
Expand All @@ -338,12 +362,20 @@ export default function runner(currentPlugin: PluginCreator<unknown>) {
{ file: normalizeFilePathForGithubAnnotation(expectFilePath), line: 1, col: 1 },
));
} else {
failureSummary.add(testCaseLabel);
console.error(formatWarningsAssertError(testCaseLabel, testCaseOptions, result.warnings().length, testCaseOptions.warnings));
}
}
}
}

if (failureSummary.size) {
console.error('\nunexpected failures:');
for (const label of failureSummary.values()) {
console.error(' - ' + label);
}
}

if (hasErrors) {
process.exit(1);
}
Expand Down
3 changes: 3 additions & 0 deletions packages/postcss-tape/test-self/basic.break-css.expect.log
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ basic:break-css
result was not parsable with PostCSS.

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

unexpected failures:
- basic:break-css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ basic:broken-sourcemap
broken source map: ["basic.css","<no source>"]

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

unexpected failures:
- basic:broken-sourcemap
3 changes: 3 additions & 0 deletions packages/postcss-tape/test-self/basic.postcss-8-3.expect.log
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ output changed :
^

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

unexpected failures:
- basic:postcss-8-3
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,6 @@ output changed :
^

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

unexpected failures:
- basic:with-diff-in-expect
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,8 @@ unexpected or missing warnings :
- expected 7

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

unexpected failures:
- basic:with-one-missing-warning
- basic:with-one-unexpected-warning
- basic:with-multiple-warnings
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@ basic:without-expect
missing or broken "expect" file: "basic.without-expect.expect.css"

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

unexpected failures:
- basic:without-expect
6 changes: 6 additions & 0 deletions plugin-packs/postcss-preset-env/.tape.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ postcssTape(plugin)({
browsers: 'chrome >= 38'
}
},
'basic:ie10': {
message: 'supports { browsers: "ie >= 10" } usage',
options: {
browsers: 'ie >= 10'
}
},
'basic:ch88-ff78': {
message: 'uses :is pseudo for nesting with modern browsers { browsers: "chrome >= 88, firefox >= 78", stage: 0 }',
options: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,24 @@ export default function getOptionsForBrowsersByFeature(browsers, feature, cssdb)

return {};

case 'any-link-pseudo-class':
{
const hasIEOrEdge = supportedBrowsers.find((browserslistEntry) => {
return browserslistEntry.startsWith('ie ') || browserslistEntry.startsWith('edge ');
});

if (hasIEOrEdge) {
log('Adding area[href] fallbacks for ":any-link" support in Edge and IE.');
return {
subFeatures: {
areaHrefNeedsFixing: true,
},
};
}
}

return {};

default:
return {};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
order: 22;
}

.test-any-link-pseudo-class:link,.test-any-link-pseudo-class:visited {
.test-any-link-pseudo-class:link, .test-any-link-pseudo-class:visited, area.test-any-link-pseudo-class[href] {
order: 23;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
order: 22;
}

.test-any-link-pseudo-class:link,.test-any-link-pseudo-class:visited {
.test-any-link-pseudo-class:link, .test-any-link-pseudo-class:visited, area.test-any-link-pseudo-class[href] {
order: 23;
}

Expand Down
2 changes: 1 addition & 1 deletion plugin-packs/postcss-preset-env/test/basic.expect.css
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@
order: 22;
}

.test-any-link-pseudo-class:link,.test-any-link-pseudo-class:visited {
.test-any-link-pseudo-class:link, .test-any-link-pseudo-class:visited, area.test-any-link-pseudo-class[href] {
order: 23;
}

Expand Down
Loading