Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
tizmagik committed Aug 31, 2016
1 parent 28dbed8 commit f6aa376
Showing 1 changed file with 78 additions and 0 deletions.
78 changes: 78 additions & 0 deletions tests/src/rules/max-dependencies.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { test } from '../utils'

import { RuleTester } from 'eslint'

const ruleTester = new RuleTester()
, rule = require('rules/max-dependencies')

ruleTester.run('max-dependencies', rule, {
valid: [
test({ code: 'import "./foo.js"' }),

test({ code: 'import "./foo.js"; import "./bar.js";',
options: [{
max: 2,
}],
}),

test({ code: 'import "./foo.js"; import "./bar.js"; const a = require("./foo.js"); const b = require("./bar.js");',
options: [{
max: 2,
}],
}),

test({ code: 'import {x, y, z} from "./foo"'}),
],
invalid: [
test({
code: 'import { x } from \'./foo\'; import { y } from \'./foo\'; import {z} from \'./bar\';',
options: [{
max: 1,
}],
errors: [
'Maximum number of dependencies (1) exceeded.',
],
}),

test({
code: 'import { x } from \'./foo\'; import { y } from \'./bar\'; import { z } from \'./baz\';',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),

test({
code: 'import { x } from \'./foo\'; require("./bar"); import { z } from \'./baz\';',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),

test({
code: 'import { x } from \'./foo\'; import { z } from \'./foo\'; require("./bar"); const path = require("path");',
options: [{
max: 2,
}],
errors: [
'Maximum number of dependencies (2) exceeded.',
],
}),

test({
code: 'import type { x } from \'./foo\'; import type { y } from \'./bar\'',
parser: 'babel-eslint',
options: [{
max: 1,
}],
errors: [
'Maximum number of dependencies (1) exceeded.',
],
}),
],
})

0 comments on commit f6aa376

Please sign in to comment.