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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor to remove callbacks in test examples #6149

Merged
merged 2 commits into from
Jun 20, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 16 additions & 16 deletions lib/__tests__/printConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@ const pluginWarnAboutFoo = require('./fixtures/plugin-warn-about-foo');
const printConfig = require('../printConfig');
const replaceBackslashes = require('../testUtils/replaceBackslashes');

it('printConfig uses getConfigForFile to retrieve the config', () => {
it('printConfig uses getConfigForFile to retrieve the config', async () => {
const filepath = replaceBackslashes(
path.join(__dirname, 'fixtures/getConfigForFile/a/b/foo.css'),
);

return printConfig({
const result = await printConfig({
files: [filepath],
}).then((result) => {
});

expect(result).toEqual({
plugins: [path.join(__dirname, '/fixtures/plugin-warn-about-foo.js')],
rules: {
Expand All @@ -24,51 +25,50 @@ it('printConfig uses getConfigForFile to retrieve the config', () => {
},
});
});
});

it('config overrides should apply', () => {
it('config overrides should apply', async () => {
const filepath = replaceBackslashes(
path.join(__dirname, 'fixtures/config-overrides/testPrintConfig/style.css'),
);

return printConfig({
const result = await printConfig({
files: [filepath],
}).then((result) => {
});

expect(result).toEqual({
rules: {
'block-no-empty': [true],
'color-named': ['never'],
},
});
});
});

it('printConfig with input css should throw', () => {
return expect(
it('printConfig with input css should throw', async () => {
await expect(
printConfig({
code: 'a {}',
}),
).rejects.toThrow('The --print-config option must be used with exactly one file path.');
});

it('printConfig with no path should throw', () => {
return expect(
it('printConfig with no path should throw', async () => {
await expect(
printConfig({
files: [],
}),
).rejects.toThrow('The --print-config option must be used with exactly one file path.');
});

it('printConfig with multiple paths should throw', () => {
return expect(
it('printConfig with multiple paths should throw', async () => {
await expect(
printConfig({
files: ['./first-path.css', './second-path.css'],
}),
).rejects.toThrow('The --print-config option must be used with exactly one file path.');
});

it('printConfig with globs should throw', () => {
return expect(
it('printConfig with globs should throw', async () => {
await expect(
printConfig({
files: ['./*.css'],
}),
Expand Down
48 changes: 30 additions & 18 deletions lib/__tests__/processors.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,19 @@ const fixturesPath = path.join(__dirname, './fixtures');
describe('processor transforms input and output', () => {
let results;

beforeEach(() => {
beforeEach(async () => {
const code = 'one\ntwo\n```start\na {}\nb { color: pink }\n```end\nthree';

return standalone({
const data = await standalone({
code,
config: {
extends: './config-block-no-empty',
processors: './processor-fenced-blocks',
},
configBasedir: fixturesPath,
}).then((data) => (results = data.results));
});

results = data.results;
});

it('number of results', () => {
Expand Down Expand Up @@ -49,17 +51,19 @@ describe('processor transforms input and output', () => {
describe('processor accepts options', () => {
let results;

beforeEach(() => {
beforeEach(async () => {
const code = 'one\ntwo\n```start\na {}\nb { color: pink }\n```end\nthree';

return standalone({
const data = await standalone({
code,
config: {
extends: './config-block-no-empty',
processors: [['./processor-fenced-blocks', { specialMessage: 'options worked' }]],
},
configBasedir: fixturesPath,
}).then((data) => (results = data.results));
});

results = data.results;
});

it('special message', () => {
Expand All @@ -70,12 +74,12 @@ describe('processor accepts options', () => {
describe('multiple processors', () => {
let results;

beforeEach(() => {
beforeEach(async () => {
const code =
'one\ntwo\n```start\na {}\nb { color: pink }\n```end\nthree???startc {}???end' +
'\n\n???start```start\na {}\nb { color: pink }\n```end???end';

return standalone({
const data = await standalone({
code,
config: {
extends: './config-block-no-empty',
Expand All @@ -85,7 +89,9 @@ describe('multiple processors', () => {
],
},
configBasedir: fixturesPath,
}).then((data) => (results = data.results));
});

results = data.results;
});

it('number of results', () => {
Expand Down Expand Up @@ -130,12 +136,12 @@ describe('loading processors (and extend) from process.cwd', () => {
process.chdir(actualCwd);
});

beforeEach(() => {
beforeEach(async () => {
const code =
'one\ntwo\n```start\na {}\nb { color: pink }\n```end\nthree???startc {}???end' +
'\n\n???start```start\na {}\nb { color: pink }\n```end???end';

return standalone({
const data = await standalone({
code,
config: {
extends: './__tests__/fixtures/config-block-no-empty',
Expand All @@ -144,7 +150,9 @@ describe('loading processors (and extend) from process.cwd', () => {
['./__tests__/fixtures/processor-fenced-blocks', { specialMessage: 'options worked' }],
],
},
}).then((data) => (results = data.results));
});

results = data.results;
});

it('number of results', () => {
Expand All @@ -167,12 +175,12 @@ describe('loading processors (and extend) from process.cwd', () => {
describe('loading processors (and extend) from options.cwd', () => {
let results;

beforeEach(() => {
beforeEach(async () => {
const code =
'one\ntwo\n```start\na {}\nb { color: pink }\n```end\nthree???startc {}???end' +
'\n\n???start```start\na {}\nb { color: pink }\n```end???end';

return standalone({
const data = await standalone({
code,
config: {
extends: './__tests__/fixtures/config-block-no-empty',
Expand All @@ -182,7 +190,9 @@ describe('loading processors (and extend) from options.cwd', () => {
],
},
cwd: path.join(__dirname, '..'),
}).then((data) => (results = data.results));
});

results = data.results;
});

it('number of results', () => {
Expand All @@ -205,17 +215,19 @@ describe('loading processors (and extend) from options.cwd', () => {
describe('processor gets to modify result on CssSyntaxError', () => {
let results;

beforeEach(() => {
beforeEach(async () => {
const code = "one\ntwo\n```start\na {}\nb { color: 'pink; }\n```end\nthree";

return standalone({
const data = await standalone({
code,
config: {
rules: { 'block-no-empty': true },
processors: './processor-fenced-blocks',
},
configBasedir: fixturesPath,
}).then((data) => (results = data.results));
});

results = data.results;
});

it('CssSyntaxError occurred', () => {
Expand Down
36 changes: 12 additions & 24 deletions lib/__tests__/reportDisables.test.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
'use strict';

const standalone = require('../standalone');
const stripIndent = require('common-tags').stripIndent;
const { stripIndent } = require('common-tags');

describe('reportDisables', () => {
it('reports a disabled comment', () => {
it('reports a disabled comment', async () => {
const config = {
rules: { 'block-no-empty': [true, { reportDisables: true }] },
};
Expand All @@ -18,13 +18,10 @@ describe('reportDisables', () => {
}
`;

return standalone({ config, code: css }).then((linted) => {
const results = linted.results;
const { results } = await standalone({ config, code: css });

expect(results).toHaveLength(1);
const warnings = results[0].warnings;

expect(warnings).toEqual([
expect(results[0].warnings).toEqual([
{
line: 1,
column: 1,
Expand All @@ -45,9 +42,8 @@ describe('reportDisables', () => {
},
]);
});
});

it('reports an ignored disabled comment', () => {
it('reports an ignored disabled comment', async () => {
const config = {
rules: { 'block-no-empty': [true, { reportDisables: true }] },
};
Expand All @@ -61,17 +57,14 @@ describe('reportDisables', () => {
}
`;

return standalone({
const { results } = await standalone({
config,
code: css,
ignoreDisables: true,
}).then((linted) => {
const results = linted.results;
});

expect(results).toHaveLength(1);
const warnings = results[0].warnings;

expect(warnings.filter((warning) => warning.rule === 'reportDisables')).toEqual([
expect(results[0].warnings.filter((warning) => warning.rule === 'reportDisables')).toEqual([
{
line: 1,
column: 1,
Expand All @@ -92,9 +85,8 @@ describe('reportDisables', () => {
},
]);
});
});

it("doesn't report disables by default", () => {
it("doesn't report disables by default", async () => {
const config = {
rules: { 'block-no-empty': [true] },
};
Expand All @@ -108,16 +100,14 @@ describe('reportDisables', () => {
}
`;

return standalone({ config, code: css }).then((linted) => {
const results = linted.results;
const { results } = await standalone({ config, code: css });

expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(0);
});
});

// This should be handled by the global `reportUnscopedDisables` option (#2292).
it("doesn't report unscoped disables", () => {
it("doesn't report unscoped disables", async () => {
const config = {
rules: { 'block-no-empty': [true, { reportDisables: true }] },
};
Expand All @@ -126,11 +116,9 @@ describe('reportDisables', () => {
a {} /* stylelint-disable-line */
`;

return standalone({ config, code: css }).then((linted) => {
const results = linted.results;
const { results } = await standalone({ config, code: css });

expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(0);
});
});
});