Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
m-allanson committed Jul 16, 2020
1 parent ec76d52 commit 30a1b09
Showing 1 changed file with 144 additions and 100 deletions.
244 changes: 144 additions & 100 deletions lib/__tests__/standalone-globs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,62 +14,46 @@ const standalone = require('../standalone');

const fixturesPath = replaceBackslashes(path.join(__dirname, 'fixtures', 'globs'));

/**
*
Failing tests for https://github.com/stylelint/stylelint/issues/4521
How to fix?
use fast-glob.escapePath() ? https://github.com/mrmlnc/fast-glob#escapepathpattern
try this:
if hasMagic
escapePath
is escapedPath an exact file match? if yes, use it
otherwise,
fall back to globbing
// see static vs dynamic paths https://github.com/mrmlnc/fast-glob#what-is-a-static-or-dynamic-pattern
*/
// Tests for https://github.com/stylelint/stylelint/issues/4521

describe('standalone globbing', () => {
// https://github.com/stylelint/stylelint/issues/4193
it('static path contains "got(brackets)"', async () => {
const cssPath = `${fixturesPath}/with(brackets)/styles.css`;
describe('paths with special characters', () => {
// ref https://github.com/micromatch/micromatch#matching-features
const fixtureDirs = [
`[digit]/not-digits`,
`with spaces`,
`extglob?(s)`,
`got!negate/negate`,
// `extglob+(s)`, // Note: +'s cause errors. Ignoring until it becomes a problem
];

const { results } = await standalone({
files: cssPath,
config: {
rules: {
'block-no-empty': true,
},
},
// https://github.com/stylelint/stylelint/issues/4193
it.each(fixtureDirs)(`static path contains "%s"`, async (fixtureDir) => {
const cssPath = `${fixturesPath}/${fixtureDir}/styles.css`;

const { results } = await standalone({
files: cssPath,
config: { rules: { 'block-no-empty': true } },
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
});

// https://github.com/stylelint/stylelint/issues/4193
it('static path contains "got [many] (special) + !chars"', async () => {
const cssPath = `${fixturesPath}/with [many] (special) + !characters/styles.css`;
// https://github.com/stylelint/stylelint/issues/4211
it('glob has no + character, matched path does', async () => {
const files = `${fixturesPath}/**/glob-plus.css`; // file is in dir 'glob+chars'

const { results } = await standalone({
files: cssPath,
config: {
rules: {
'block-no-empty': true,
},
},
files,
config: { rules: { 'block-no-empty': true } },
});

expect(results).toHaveLength(1);
Expand All @@ -82,38 +66,13 @@ describe('standalone globbing', () => {
);
});

// https://github.com/stylelint/stylelint/issues/4211
it('glob has no + character, matched path does', async () => {
const cssGlob = `${fixturesPath}/**/glob-plus.css`; // file is in dir 'glob+chars'

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).objectContaining({
rule: 'block-no-empty',
severity: 'error',
});
});

// https://github.com/stylelint/stylelint/issues/4211
it('glob contains + character, matched path does not', async () => {
const cssGlob = `${fixturesPath}/glob-contains-plus+/*.css`; // file is in dir 'glob+chars'
const files = `${fixturesPath}/+(g)lob-contains-plus/*.css`;

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
files,
config: { rules: { 'block-no-empty': true } },
});

expect(results).toHaveLength(1);
Expand All @@ -129,18 +88,14 @@ describe('standalone globbing', () => {
// https://github.com/stylelint/stylelint/issues/3272
// should ignore 'negated-globs/ignore/styles.css'
it('negated glob patterns', async () => {
const cssGlob = [
const files = [
`${fixturesPath}/negated-globs/**/*.css`,
`!${fixturesPath}/negated-globs/ignore/**/*.css`,
];

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
files,
config: { rules: { 'block-no-empty': true } },
});

// ensure that the only result is from the unignored file
Expand All @@ -156,26 +111,115 @@ describe('standalone globbing', () => {
);
});

// https://github.com/stylelint/stylelint/issues/4855
it('glob with special chars matches path with special chars', async () => {
const cssGlob = `${fixturesPath}/[glob-and-path]/sub-dir/*.css`;
describe('mixed globs and paths with special chars', () => {
it('manual escaping', async () => {
const cssGlob = `${fixturesPath}/got\\[braces\\] and \\(spaces\\)/*.+(s|c)ss`;

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
},
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
it('setting "cwd" in globbyOptions', async () => {
const cssGlob = `*.+(s|c)ss`;

const { results } = await standalone({
files: cssGlob,
config: {
rules: {
'block-no-empty': true,
},
},
globbyOptions: {
cwd: `${fixturesPath}/got[braces] and (spaces)/`,
},
});

expect(results).toHaveLength(1);
expect(results[0].errored).toEqual(true);
expect(results[0].warnings[0]).toEqual(
expect.objectContaining({
rule: 'block-no-empty',
severity: 'error',
}),
);
});

/* eslint-disable jest/no-commented-out-tests -- Failing case for reference. Documents behaviour that doesn't work. */

// Note: This fails because there's no way to tell which parts of the glob are literal characters, and which are special globbing characters.
//
// 'got[braces] and (spaces)' is a literal directory path. `*.+(s|c)ss` is a glob.

// https://github.com/stylelint/stylelint/issues/4855
// it('glob and matched path contain different special chars, complex example', async () => {
// const cssGlob = `${fixturesPath}/got[braces] and (spaces)/*.+(s|c)ss`;

// const { results } = await standalone({
// files: cssGlob,
// config: {
// rules: {
// 'block-no-empty': true,
// },
// },
// });

// expect(results).toHaveLength(1);
// expect(results[0].errored).toEqual(true);
// expect(results[0].warnings[0]).toEqual(
// expect.objectContaining({
// rule: 'block-no-empty',
// severity: 'error',
// }),
// );
// });

/* eslint-enable */
});
});

// const cases = [
// // [`glob and matched path contain different special chars`, `${fixturesPath}/[glob-and-path]/*.css`, undefined],
// // [`complex example`, `${fixturesPath}/got[braces] and (spaces)/*.+(s|c)ss`, undefined],

// // description, glob, globbyOptions
// [`manual escaping`, `${fixturesPath}/got\\[braces\\] and \\(spaces\\)/*.+(s|c)ss`, undefined],
// [
// `using cwd globbyOption`,
// `*.+(s|c)ss`,
// {
// cwd: `${fixturesPath}/got[braces] and (spaces)/`,
// },
// ],
// ];

// it.each(cases)(`%s`, async (_, glob, globbyOptions) => {
// const { results } = await standalone({
// files: glob,
// globbyOptions,
// config: { rules: { 'block-no-empty': true } },
// });

// expect(results).toHaveLength(1);
// expect(results[0].errored).toEqual(true);
// expect(results[0].warnings[0]).toEqual(
// expect.objectContaining({
// rule: 'block-no-empty',
// severity: 'error',
// }),
// );
// });

0 comments on commit 30a1b09

Please sign in to comment.