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 tests to remove deprecated output property as possible #7300

Merged
merged 1 commit into from
Nov 6, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions lib/__tests__/extends.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -19,42 +19,42 @@ const configExtendingThreeWithOverride = readJSONFile(
const fixturesPath = fileURLToPath(new URL('./fixtures', import.meta.url));

it('basic extending', async () => {
const linted = await standalone({
const { report, results } = await standalone({
code: 'a {}',
config: configExtendingOne,
configBasedir: fixturesPath,
});

expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});

it('basic extending with object', async () => {
const linted = await standalone({
const { report, results } = await standalone({
code: 'a {}',
config: configExtendingWithObject,
configBasedir: fixturesPath,
});

expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});

it('recursive extending', async () => {
const linted = await standalone({
const { report, results } = await standalone({
code: 'a {}',
config: configExtendingAnotherExtend,
configBasedir: fixturesPath,
});

expect(typeof linted.output).toBe('string');
expect(linted.results).toHaveLength(1);
expect(linted.results[0].warnings).toHaveLength(1);
expect(linted.results[0].warnings[0].rule).toBe('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});

it('extending with overrides', async () => {
Expand Down
4 changes: 2 additions & 2 deletions lib/__tests__/standalone-deprecations.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ const configBlockNoEmpty = readJSONFile(

describe('standalone with deprecations', () => {
it('works', async () => {
const { output, results } = await standalone({
const { report, results } = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
});

expect(output).toContain('Some deprecation');
expect(report).toContain('Some deprecation');
expect(results).toHaveLength(1);
expect(results[0].deprecations).toHaveLength(1);
expect(results[0].deprecations[0].text).toBe('Some deprecation');
Expand Down
4 changes: 0 additions & 4 deletions lib/__tests__/standalone-fix.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ it('outputs fixed code when input is code string', async () => {

expect(result.code).toBe('a { color: #fff; }');
expect(result.report).toBe('');
expect(result.output).toBe('a { color: #fff; }'); // TODO: Deprecated. Remove in the next major version.
});

it('fixes when enabled in config', async () => {
Expand All @@ -45,7 +44,6 @@ it('fixes when enabled in config', async () => {

expect(result.code).toBe('a { color: #fff; }');
expect(result.report).toBe('');
expect(result.output).toBe('a { color: #fff; }'); // TODO: Deprecated. Remove in the next major version.
});

it("doesn't fix with stylelint-disable commands", async () => {
Expand All @@ -66,7 +64,6 @@ it("doesn't fix with stylelint-disable commands", async () => {

expect(result.code).toBe(code);
expect(result.report).toBe('');
expect(result.output).toBe(code); // TODO: Deprecated. Remove in the next major version.
});

it("doesn't fix with scoped stylelint-disable commands", async () => {
Expand Down Expand Up @@ -178,7 +175,6 @@ describe('writing fixes to files', () => {

2 problems (2 errors, 0 warnings)
`);
expect(result.output).toMatch('stylesheet.css'); // TODO: Deprecated. Remove in the next major version.
});

it("doesn't write to ignored file", async () => {
Expand Down
16 changes: 6 additions & 10 deletions lib/__tests__/standalone-formatter.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,30 +9,26 @@ const configBlockNoEmpty = readJSONFile(
);

it('standalone with input css and alternate formatter specified by keyword', async () => {
const { output } = await standalone({
const { report } = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
formatter: 'string',
});

expect(typeof output).toBe('string');

const strippedOutput = stripAnsi(output);
const strippedOutput = stripAnsi(report);

expect(strippedOutput).toContain('1:3');
expect(strippedOutput).toContain('block-no-empty');
});

it('standalone with input css and alternate formatter function', async () => {
const { output } = await standalone({
const { report } = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
formatter: stringFormatter,
});

expect(typeof output).toBe('string');

const strippedOutput = stripAnsi(output);
const strippedOutput = stripAnsi(report);

expect(strippedOutput).toContain('1:3');
expect(strippedOutput).toContain('block-no-empty');
Expand All @@ -51,13 +47,13 @@ it('standalone with invalid formatter option', async () => {
});

it('standalone with input css and custom promised formatter', async () => {
const { output } = await standalone({
const { report } = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
formatter: Promise.resolve((results) => {
return results[0].warnings.map((w) => w.rule).join();
}),
});

expect(output).toContain('block-no-empty');
expect(report).toContain('block-no-empty');
});
40 changes: 20 additions & 20 deletions lib/__tests__/standalone.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const fixturesPath = replaceBackslashes(new URL('./fixtures', import.meta.url));
const __dirname = fileURLToPath(new URL('.', import.meta.url));

describe('standalone with one input file', () => {
let output;
let report;
let results;

beforeEach(async () => {
Expand All @@ -26,28 +26,28 @@ describe('standalone with one input file', () => {
configFile: path.join(__dirname, 'fixtures/config-block-no-empty.json'),
});

output = data.output;
report = data.report;
results = data.results;
});

it('triggers warning', () => {
expect(output).toContain('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});
});

it('standalone with two file-specific globs', async () => {
const { output, results } = await standalone({
const { report, results } = await standalone({
files: [`${fixturesPath}/e*y-block.*`, `${fixturesPath}/invalid-h*.css`],
config: {
rules: { 'block-no-empty': true, 'color-no-invalid-hex': true },
},
});

expect(output).toContain('block-no-empty');
expect(output).toContain('color-no-invalid-hex');
expect(report).toContain('block-no-empty');
expect(report).toContain('color-no-invalid-hex');
expect(results).toHaveLength(2);
expect(results[0].warnings).toHaveLength(1);
expect(results[1].warnings).toHaveLength(1);
Expand Down Expand Up @@ -81,7 +81,7 @@ it('standalone with two file-specific globs', async () => {
});

describe('standalone with files and globbyOptions', () => {
let output;
let report;
let results;

beforeEach(async () => {
Expand All @@ -92,20 +92,20 @@ describe('standalone with files and globbyOptions', () => {
configFile: path.join(__dirname, 'fixtures/config-block-no-empty.json'),
});

output = data.output;
report = data.report;
results = data.results;
});

it('triggers warning', () => {
expect(output).toContain('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});
});

describe('standalone with files and cwd', () => {
let output;
let report;
let results;

beforeEach(async () => {
Expand All @@ -116,25 +116,25 @@ describe('standalone with files and cwd', () => {
configFile: path.join(__dirname, 'fixtures/config-block-no-empty.json'),
});

output = data.output;
report = data.report;
results = data.results;
});

it('triggers warning', () => {
expect(output).toContain('block-no-empty');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
});
});

it('standalone with input css', async () => {
const { output, results } = await standalone({
const { report, results } = await standalone({
code: 'a {}',
config: configBlockNoEmpty,
});

expect(typeof output).toBe('string');
expect(report).toContain('block-no-empty');
expect(results).toHaveLength(1);
expect(results[0].warnings).toHaveLength(1);
expect(results[0].warnings[0].rule).toBe('block-no-empty');
Expand All @@ -161,37 +161,37 @@ it('standalone with nonexistent-file throws an error', async () => {
});

it('standalone with nonexistent-file and allowEmptyInput enabled quietly exits', async () => {
const { results, errored, output } = await standalone({
const { results, errored, report } = await standalone({
files: `${fixturesPath}/nonexistent-file.css`,
config: configBlockNoEmpty,
allowEmptyInput: true,
});

expect(results).toHaveLength(0);
expect(errored).toBe(false);
expect(output).toBe('[]');
expect(report).toBe('[]');
});

it('standalone with nonexistent-file and allowEmptyInput enabled (in config) quietly exits', async () => {
const { results, errored, output } = await standalone({
const { results, errored, report } = await standalone({
files: `${fixturesPath}/nonexistent-file.css`,
config: { ...configBlockNoEmpty, allowEmptyInput: true },
});

expect(results).toHaveLength(0);
expect(errored).toBe(false);
expect(output).toBe('[]');
expect(report).toBe('[]');
});

it('standalone with nonexistent-file and allowEmptyInput enabled (in config file) quietly exits', async () => {
const { results, errored, output } = await standalone({
const { results, errored, report } = await standalone({
files: `${fixturesPath}/nonexistent-file.css`,
configFile: `${fixturesPath}/config-allow-empty-input.json`,
});

expect(results).toHaveLength(0);
expect(errored).toBe(false);
expect(output).toBe('[]');
expect(report).toBe('[]');
});

describe('standalone passing code with syntax error', () => {
Expand Down