Skip to content

Commit

Permalink
Wrap tests in describe()
Browse files Browse the repository at this point in the history
  • Loading branch information
lahmatiy committed Oct 11, 2024
1 parent acfc0bd commit 7faadc8
Showing 1 changed file with 59 additions and 57 deletions.
116 changes: 59 additions & 57 deletions test/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,61 +58,63 @@ function run(...cliArgs) {
return wrapper;
}

it('should output version', () =>
run('-v')
.stdout(version)
);

it('should output help', () =>
run('-h')
.stdout(/Usage:/)
);

it('should read content from stdin if no file specified', () =>
run()
.stdin(fixtureContent('css/style.css'))
.stderr(fixtureContent('css/style.validate-result')
.replace(/^#.+\n/, '# <stdin>\n')
)
);

it('should read from file', () =>
run(path.relative(process.cwd(), fixturePath('css/style.css')))
.stderr(fixtureContent('css/style.validate-result'))
);

it('should error when wrong reporter', () =>
run(path.relative(process.cwd(), fixturePath('css/style.css')), '--reporter', 'bad-value')
.stderr('Wrong value for reporter: bad-value')
);

it('should error when file doesn\'t exist', () =>
run('not/exists.css')
.stderr('ERROR! No such file or directory: not/exists.css')
);

describe('custom reporter', () => {
const cwd = path.resolve('fixtures/custom-reporter');
const tests = {
// module
'ESM module': 'custom-reporter.js',
'commonjs module': 'custom-reporter.cjs',

// package
'commonjs package': 'commonjs',
'commonjs package (path to dir)': 'commonjs/lib',
'commonjs package (full path)': 'commonjs/lib/index.js',
'esm package': 'esm',
'esm package (full path)': 'esm/lib/index.js',
'dual package': 'dual',
'dual package (full path)': 'dual/lib/index.js',
'dual package (full path to cjs)': 'dual/lib/index.cjs'
};

for (const [title, reporter] of Object.entries(tests)) {
it(title, () =>
run({ cwd }, 'style.css', '-r', reporter)
.stderr('OK')
);
}
describe('cli', () => {
it('should output version', () =>
run('-v')
.stdout(version)
);

it('should output help', () =>
run('-h')
.stdout(/Usage:/)
);

it('should read content from stdin if no file specified', () =>
run()
.stdin(fixtureContent('css/style.css'))
.stderr(fixtureContent('css/style.validate-result')
.replace(/^#.+\n/, '# <stdin>\n')
)
);

it('should read from file', () =>
run(path.relative(process.cwd(), fixturePath('css/style.css')))
.stderr(fixtureContent('css/style.validate-result'))
);

it('should error when wrong reporter', () =>
run(path.relative(process.cwd(), fixturePath('css/style.css')), '--reporter', 'bad-value')
.stderr('Wrong value for reporter: bad-value')
);

it('should error when file doesn\'t exist', () =>
run('not/exists.css')
.stderr('ERROR! No such file or directory: not/exists.css')
);

describe('custom reporter', () => {
const cwd = path.resolve('fixtures/custom-reporter');
const tests = {
// module
'ESM module': 'custom-reporter.js',
'commonjs module': 'custom-reporter.cjs',

// package
'commonjs package': 'commonjs',
'commonjs package (path to dir)': 'commonjs/lib',
'commonjs package (full path)': 'commonjs/lib/index.js',
'esm package': 'esm',
'esm package (full path)': 'esm/lib/index.js',
'dual package': 'dual',
'dual package (full path)': 'dual/lib/index.js',
'dual package (full path to cjs)': 'dual/lib/index.cjs'
};

for (const [title, reporter] of Object.entries(tests)) {
it(title, () =>
run({ cwd }, 'style.css', '-r', reporter)
.stderr('OK')
);
}
});
});

0 comments on commit 7faadc8

Please sign in to comment.