|
| 1 | +'use strict'; |
| 2 | +const path = require('path'); |
| 3 | +const {test} = require('tap'); |
| 4 | + |
| 5 | +const {load} = require('../eslint-plugin-helper'); |
| 6 | + |
| 7 | +const projectDir = path.join(__dirname, 'fixture/eslint-plugin-helper'); |
| 8 | + |
| 9 | +test('caches loaded configuration', t => { |
| 10 | + const expected = load(projectDir); |
| 11 | + const actual = load(projectDir); |
| 12 | + t.is(expected, actual); |
| 13 | + t.end(); |
| 14 | +}); |
| 15 | + |
| 16 | +test('classifies files according to the configuration', t => { |
| 17 | + const helper = load(projectDir); |
| 18 | + t.deepEqual(helper.classifyFile(path.join(projectDir, 'tests/test.foo')), { |
| 19 | + isHelper: false, |
| 20 | + isSource: false, |
| 21 | + isTest: true |
| 22 | + }); |
| 23 | + t.deepEqual(helper.classifyFile(path.join(projectDir, 'tests/_helper.foo')), { |
| 24 | + isHelper: true, |
| 25 | + isSource: false, |
| 26 | + isTest: false |
| 27 | + }); |
| 28 | + t.deepEqual(helper.classifyFile(path.join(projectDir, 'helpers/helper.foo')), { |
| 29 | + isHelper: true, |
| 30 | + isSource: false, |
| 31 | + isTest: false |
| 32 | + }); |
| 33 | + t.deepEqual(helper.classifyFile(path.join(projectDir, 'source.foo')), { |
| 34 | + isHelper: false, |
| 35 | + isSource: true, |
| 36 | + isTest: false |
| 37 | + }); |
| 38 | + t.deepEqual(helper.classifyFile(path.join(projectDir, 'tests/test.js')), { |
| 39 | + isHelper: false, |
| 40 | + isSource: false, |
| 41 | + isTest: false |
| 42 | + }); |
| 43 | + t.end(); |
| 44 | +}); |
| 45 | + |
| 46 | +test('classifies imports with extension according to the configuration', t => { |
| 47 | + const helper = load(projectDir); |
| 48 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'tests/test.foo')), { |
| 49 | + isHelper: false, |
| 50 | + isSource: false, |
| 51 | + isTest: true |
| 52 | + }); |
| 53 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'tests/_helper.foo')), { |
| 54 | + isHelper: true, |
| 55 | + isSource: false, |
| 56 | + isTest: false |
| 57 | + }); |
| 58 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'helpers/helper.foo')), { |
| 59 | + isHelper: true, |
| 60 | + isSource: false, |
| 61 | + isTest: false |
| 62 | + }); |
| 63 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'source.foo')), { |
| 64 | + isHelper: false, |
| 65 | + isSource: true, |
| 66 | + isTest: false |
| 67 | + }); |
| 68 | + t.end(); |
| 69 | +}); |
| 70 | + |
| 71 | +test('classifies imports without extension according to the configuration', t => { |
| 72 | + const helper = load(projectDir); |
| 73 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'tests/test')), { |
| 74 | + isHelper: false, |
| 75 | + isSource: false, |
| 76 | + isTest: true |
| 77 | + }); |
| 78 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'tests/_helper')), { |
| 79 | + isHelper: true, |
| 80 | + isSource: false, |
| 81 | + isTest: false |
| 82 | + }); |
| 83 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'helpers/helper')), { |
| 84 | + isHelper: true, |
| 85 | + isSource: false, |
| 86 | + isTest: false |
| 87 | + }); |
| 88 | + t.deepEqual(helper.classifyImport(path.join(projectDir, 'source')), { |
| 89 | + isHelper: false, |
| 90 | + isSource: true, |
| 91 | + isTest: false |
| 92 | + }); |
| 93 | + t.end(); |
| 94 | +}); |
0 commit comments