Skip to content

Commit

Permalink
Refactor to remove callbacks in test examples (#6149)
Browse files Browse the repository at this point in the history
```console
$ git grep  -E '\.(then|catch|finally)' '**/*.test.js' || echo 'no match'
no match
```
  • Loading branch information
ybiquitous committed Jun 20, 2022
1 parent 169ba06 commit f67ec4e
Show file tree
Hide file tree
Showing 12 changed files with 471 additions and 489 deletions.
60 changes: 30 additions & 30 deletions lib/__tests__/printConfig.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,70 +5,70 @@ 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: {
'block-no-empty': [true],
'plugin/warn-about-foo': ['always'],
},
pluginFunctions: {
'plugin/warn-about-foo': pluginWarnAboutFoo.rule,
},
});
});

expect(result).toEqual({
plugins: [path.join(__dirname, '/fixtures/plugin-warn-about-foo.js')],
rules: {
'block-no-empty': [true],
'plugin/warn-about-foo': ['always'],
},
pluginFunctions: {
'plugin/warn-about-foo': pluginWarnAboutFoo.rule,
},
});
});

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'],
},
});
});

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

0 comments on commit f67ec4e

Please sign in to comment.