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

Add integration test using some canonical lists #142

Merged
merged 10 commits into from
Jun 3, 2021
Merged
Show file tree
Hide file tree
Changes from 8 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
8 changes: 7 additions & 1 deletion workflows/main.yml → .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ jobs:
fail-fast: false
matrix:
node-version:
- 16
- 14
- 12
- 10
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
submodules: true
fetch-depth: 0
- uses: actions/setup-node@v2
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
env:
github_token: ${{ secrets.GITHUB_TOKEN }}
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "test/canonical/awesome-nodejs"]
path = test/canonical/awesome-nodejs
url = https://github.com/sindresorhus/awesome-nodejs.git
[submodule "test/canonical/awesome"]
path = test/canonical/awesome
url = https://github.com/sindresorhus/awesome.git
1 change: 1 addition & 0 deletions test/canonical/awesome
Submodule awesome added at 4e59fb
1 change: 1 addition & 0 deletions test/canonical/awesome-nodejs
Submodule awesome-nodejs added at 94bb62
51 changes: 51 additions & 0 deletions test/integration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import test from 'ava';
import execa from 'execa';
import path from 'path';

const cli = path.resolve(__dirname, '../cli.js');

/**
Factory function for checking lint errors printed by awesome-lint CLI.
NotWoods marked this conversation as resolved.
Show resolved Hide resolved

@param t - AVA test context.
@param {string} stdout - CLI output.
@param {number} numberOfErrors - How many lint errors to expect.
@returns An assertion function taking line column, lint message, and rule name as parameters.
*/
function expectLintErrors(t, stdout, numberOfErrors) {
t.regex(stdout, new RegExp(`${numberOfErrors} errors`));

return (lineColumn, message, rule) => {
t.regex(stdout, new RegExp(`${lineColumn}\\s+${message}\\s+remark-lint:${rule}`));
};
}

test('awesome', async t => {
const {stdout} = await t.throwsAsync(
execa.stdout(cli, {cwd: 'test/canonical/awesome'})
);

const expectLintError = expectLintErrors(t, stdout, 3);
expectLintError('1:1', 'Missing main list heading', 'awesome-heading');
expectLintError('55:12', '"’" is used without matching "‘"', 'match-punctuation');
expectLintError('57:1', 'The default email must be replaced with yours', 'awesome-code-of-conduct');
});

test('awesome-nodejs', async t => {
const {stdout} = await t.throwsAsync(
execa.stdout(cli, {cwd: 'test/canonical/awesome-nodejs'})
);

const expectLintError = expectLintErrors(t, stdout, 11);
expectLintError('1:1', 'Missing main list heading', 'awesome-heading');
expectLintError('56:12', '"’" is used without matching "‘"', 'match-punctuation');
expectLintError('195:3', 'https://github.com/sindresorhus/cpy', 'double-link');
expectLintError('262:3', 'https://github.com/sindresorhus/got', 'double-link');
expectLintError('273:84', 'https://github.com/sindresorhus/got', 'double-link');
NotWoods marked this conversation as resolved.
Show resolved Hide resolved
expectLintError('420:3', 'https://github.com/sindresorhus/cpy', 'double-link');
expectLintError('453:4', 'https://github.com/sindresorhus/awesome-observables', 'double-link');
expectLintError('454:4', 'https://github.com/sindresorhus/awesome-observables', 'double-link');
expectLintError('812:106', '"”" is used without matching "“"', 'match-punctuation');
expectLintError('858:58', 'List item link and description must be separated with a dash', 'awesome-list-item');
expectLintError('57:1', 'The default email must be replaced with yours', 'awesome-code-of-conduct');
});