Skip to content

Commit

Permalink
Avoid potentially flaky tests
Browse files Browse the repository at this point in the history
Stylelint doesn't always report errors in the same order. Avoid that
breaking tests by only checking one file per test case.
  • Loading branch information
BPScott committed Feb 27, 2021
1 parent 5df568d commit de42bee
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions test/stylelint-prettier-e2e.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,29 @@ const {spawnSync} = require('child_process');
const {resolve} = require('path');
const stripAnsi = require('strip-ansi');

/**
* Tests that report errors in multiple files may change the order of the files
* across multiple runs.
* To avoid flaky tests, assert the reporting of errors in one file only per
* test case. Asserting no errors are reported across multiple files is ok.
*/
describe('E2E Tests', () => {
test('CSS/SCSS files', () => {
const result = runStylelint('*.{css,scss}');
test('CSS files', () => {
const result = runStylelint('*.css');

const expectedResult = `
check.invalid.css
2:25 ✖ Replace ""x"" with "'x'" prettier/prettier
`.trim();

expect(result.output).toEqual(expectedResult);
expect(result.status).toEqual(2);
});

test('SCSS files', () => {
const result = runStylelint('*.scss');

const expectedResult = `
check.invalid.scss
2:25 ✖ Replace ""x"" with "'x'" prettier/prettier
8:14 ✖ Insert "," prettier/prettier
Expand All @@ -19,6 +34,10 @@ check.invalid.scss
expect(result.status).toEqual(2);
});

/**
* Don't act upon html-like files, as prettier already handles them as whole
* files
*/
test('HTML/Markdown/Vue files', () => {
const result = runStylelint('*.{html,md,vue}');

Expand All @@ -29,7 +48,8 @@ check.invalid.scss
});

/**
* Don't act upon CSS-in-JS files
* Don't act upon CSS-in-JS files, as prettier already handles them as whole
* files
*/
test('CSS-in-JS files', () => {
const result = runStylelint('*.{js,jsx,tsx}');
Expand Down

0 comments on commit de42bee

Please sign in to comment.