-
Notifications
You must be signed in to change notification settings - Fork 9
/
index.test.js
73 lines (58 loc) · 1.62 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
const fs = require('fs')
const path = require('path')
const { jest, afterEach, it, expect } = require('@jest/globals')
jest.mock('@thisismanta/pessimist', () => ({ parseArguments: () => ({}) }))
afterEach(() => {
jest.resetModules()
for (const item of [
'eslint.local.js',
'eslint.local.cjs',
'.eslint-plugin-local.js',
'.eslint-plugin-local.cjs',
'.eslint-plugin-local',
'.eslint-plugin-local/index.js',
'.eslint-plugin-local/index.cjs',
]) {
if (fs.existsSync(item)) {
fs.rmSync(item, { recursive: true })
}
}
})
it('throws when ".eslint-plugin-local" is missing', () => {
expect(() => {
require('./index')
}).toThrow(/\.eslint-plugin-local/)
})
it('throws when ".eslint-plugin-local/index" is missing', () => {
fs.mkdirSync('.eslint-plugin-local')
expect(() => {
require('./index')
}).toThrow(/\.eslint-plugin-local/)
})
it('exports meta', () => {
fs.writeFileSync('.eslint-plugin-local.js', 'module.exports = {}')
const { meta } = require('./index')
expect(meta).toMatchObject({
name: 'eslint-plugin-local',
version: expect.stringMatching(/\d+\.\d+\.\d+/),
})
})
it.each([
['eslint.local.js'],
['eslint.local.cjs'],
['.eslint-plugin-local.js'],
['.eslint-plugin-local.cjs'],
])('exports "%s"', (item) => {
fs.writeFileSync(item, 'module.exports = { data: 123 }')
const { data } = require('./index')
expect(data).toBe(123)
})
it.each([
['.eslint-plugin-local/index.js'],
['.eslint-plugin-local/index.cjs'],
])('exports "%s"', (item) => {
fs.mkdirSync(path.dirname(item))
fs.writeFileSync(item, 'module.exports = { data: 123 }')
const { data } = require('./index')
expect(data).toBe(123)
})