Skip to content
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

Refactor lib/__tests__/integration.test.js #5284

Merged
merged 2 commits into from
May 12, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
124 changes: 63 additions & 61 deletions lib/__tests__/integration.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@ const path = require('path');
const postcss = require('postcss');
const sassSyntax = require('postcss-sass');
const scssSyntax = require('postcss-scss');
const { stripIndent } = require('common-tags');

const stylelint = require('..');

const fixtures = (...elem) => path.join(__dirname, 'fixtures', ...elem);

const config = {
rules: {
'block-opening-brace-newline-after': 'always',
Expand All @@ -26,36 +30,33 @@ const config = {
},
};

const css = `
a { background: pink; }
const css = stripIndent`
a { background: pink; }

b {
height: 1rem;
display: block;
width: 10px;
color: #zzz;
}
b {
height: 1rem;
display: block;
width: 10px;
color: #zzz;
}

/* stylelint-disable color-no-invalid-hex */
.foo {
color: #yyy;
}
/* stylelint-enable */
/* stylelint-disable color-no-invalid-hex */
.foo {
color: #yyy;
}
/* stylelint-enable */

.bar:before {
color: #mmm;
height: calc(1rem - 100%)
}
`;
.bar:before {
color: #mmm;
height: calc(1rem - 100%)
}
`;

describe('integration test expecting warnings', () => {
let result;

beforeEach(() => {
return postcss()
.use(stylelint(config))
.process(css, { from: undefined })
.then((data) => (result = data));
beforeEach(async () => {
result = await postcss().use(stylelint(config)).process(css, { from: undefined });
});

it('number and type', () => {
Expand Down Expand Up @@ -103,61 +104,62 @@ describe('integration test expecting warnings', () => {
});
});

it('Less integration test', () => {
const less = `.foo(@bar) {
color: @bar;
}
`;
it('Less integration test', async () => {
const less = stripIndent`
.foo(@bar) {
color: @bar;
}
`;

return postcss()
const result = await postcss()
.use(stylelint({ rules: {} }))
.process(less, { syntax: lessSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
.process(less, { syntax: lessSyntax, from: undefined });

expect(result.messages).toHaveLength(0);
});

it('Sass integration test', () => {
const sass = `.foo-#{variable}
color: $color`;
it('Sass integration test', async () => {
const sass = stripIndent`
.foo-#{variable}
color: $color
`;

return postcss()
const result = await postcss()
.use(stylelint({ rules: {} }))
.process(sass, { syntax: sassSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
.process(sass, { syntax: sassSyntax, from: undefined });

expect(result.messages).toHaveLength(0);
});

it('Scss integration test', () => {
const scss = `.foo-#{variable} {
color: $color;
}
`;
it('Scss integration test', async () => {
const scss = stripIndent`
.foo-#{variable} {
color: $color;
}
`;

return postcss()
const result = await postcss()
.use(stylelint({ rules: {} }))
.process(scss, { syntax: scssSyntax, from: undefined })
.then((result) => {
expect(result.messages).toHaveLength(0);
});
.process(scss, { syntax: scssSyntax, from: undefined });

expect(result.messages).toHaveLength(0);
});

describe('integration test null option', () => {
let results;

beforeEach(() => {
return stylelint
.lint({
beforeEach(async () => {
results = (
await stylelint.lint({
config: {
extends: [path.join(__dirname, 'fixtures/config-no-pixels')],
extends: [fixtures('config-no-pixels')],
rules: {
'unit-disallowed-list': null,
},
},
code: 'a { top: 10px; }',
})
.then((data) => (results = data.results));
).results;
});

it('no invalid option warnings', () => {
Expand All @@ -172,18 +174,18 @@ describe('integration test null option', () => {
describe('integration test [null] option', () => {
let results;

beforeEach(() => {
return stylelint
.lint({
beforeEach(async () => {
results = (
await stylelint.lint({
config: {
extends: [path.join(__dirname, 'fixtures/config-no-pixels')],
extends: [fixtures('config-no-pixels')],
rules: {
'unit-disallowed-list': [null],
},
},
code: 'a { top: 10px; }',
})
.then((data) => (results = data.results));
).results;
});

it('no invalid option warnings', () => {
Expand Down