Skip to content

Commit

Permalink
test(plugin-eslint): add test case and improve test docs
Browse files Browse the repository at this point in the history
  • Loading branch information
matejchalk committed Oct 9, 2023
1 parent 890cf4c commit 6440590
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
8 changes: 8 additions & 0 deletions packages/plugin-eslint/src/lib/eslint-plugin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,12 @@ describe('eslintPlugin', () => {
eslintPlugin({ eslintrc: '.eslintrc.json' }),
).rejects.toThrowError('patterns');
});

it("should throw if eslintrc file doesn't exist", async () => {
await expect(
eslintPlugin({ eslintrc: '.eslintrc.yml', patterns: '**/*.js' }),
).rejects.toThrowError(
'Failed to load config ".eslintrc.yml" to extend from',
);
});
});
11 changes: 8 additions & 3 deletions packages/plugin-eslint/src/lib/meta/rules.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ describe('listRules', () => {
});
});

describe('Nx monorepo', () => {
describe('Nx monorepo project', () => {
const nxRootDir = join(fixturesDir, 'nx-monorepo');
const eslintrc = join(nxRootDir, 'packages/utils/.eslintrc.json');

Expand All @@ -109,6 +109,7 @@ describe('listRules', () => {
});

it('should include explicitly set plugin rule with custom options', async () => {
// set in root .eslintrc.json
await expect(listRules(eslint, patterns)).resolves.toContainEqual({
ruleId: '@nx/enforce-module-boundaries',
meta: {
Expand Down Expand Up @@ -146,6 +147,7 @@ describe('listRules', () => {
});

it('should include built-in rule set implicitly by extending recommended config', async () => {
// extended via @nx/typescript -> @typescript-eslint/eslint-recommended
await expect(listRules(eslint, patterns)).resolves.toContainEqual({
ruleId: 'no-var',
meta: {
Expand All @@ -166,6 +168,7 @@ describe('listRules', () => {
});

it('should include plugin rule set implicitly by extending recommended config', async () => {
// extended via @nx/typescript -> @typescript-eslint/recommended
await expect(listRules(eslint, patterns)).resolves.toContainEqual({
ruleId: '@typescript-eslint/no-extra-semi',
meta: {
Expand All @@ -188,15 +191,17 @@ describe('listRules', () => {
} satisfies RuleData);
});

it('should not include rule which was turned off', async () => {
it('should not include rule which was turned off in extended config', async () => {
// extended TypeScript config sets "no-extra-semi": "off"
await expect(listRules(eslint, patterns)).resolves.not.toContainEqual(
expect.objectContaining({
ruleId: 'no-extra-semi',
} satisfies Partial<RuleData>),
);
});

it('should include rule added by to root config by project config', async () => {
it('should include rule added to root config by project config', async () => {
// set only in packages/utils/.eslintrc.json
await expect(listRules(eslint, patterns)).resolves.toContainEqual({
ruleId: '@nx/dependency-checks',
meta: {
Expand Down

0 comments on commit 6440590

Please sign in to comment.