const {RuleTester} = require('eslint') const avoidUnwrappedText = require('../avoid-unwrapped-text') const ruleTester = new RuleTester({ parser: require.resolve('@typescript-eslint/parser'), parserOptions: { ecmaFeatures: { jsx: true, }, ecmaVersion: 6, sourceType: 'module', }, }) describe('avoid-unwrapped-text', () => { const tests = { valid: [ { code: ` foo `, }, { code: ` foo `, }, { code: ` <> foo `, }, { code: ` {foo && foo} `, }, { code: ` {foo ? foo : bar} `, }, { code: ` foo `, }, { code: ` {foo && foo} `, }, { code: ` {foo ? foo : bar} `, }, { code: ` foo `, }, { code: ` foo `, }, { code: ` {bar} `, }, { code: ` {bar} `, }, { code: ` foo {bar} `, }, { code: ` foo `, }, { code: ` {bar} `, }, { code: ` foo {bar} `, }, { code: ` foo `, }, { code: ` foo }> `, }, { code: ` foo }> `, }, { code: ` foo : bar }> `, }, { code: ` foo }> `, }, { code: ` foo }> `, }, { code: ` foo }> `, }, { code: ` foo }> `, }, { code: ` foo : bar }> `, }, ], invalid: [ { code: ` `, errors: 1, }, { code: ` foo `, errors: 1, }, { code: ` <> foo `, errors: 1, }, { code: ` foo `, errors: 1, }, { code: ` {foo && foo} `, errors: 1, }, { code: ` {foo ? foo : bar} `, errors: 2, }, { code: ` foo `, errors: 1, }, { code: ` foo {bar} `, errors: 1, }, { code: ` foo `, errors: 1, }, { code: ` foo `, errors: 1, }, { code: ` foo }> `, errors: 1, }, { code: ` foo }> `, errors: 1, }, { code: ` foo : bar }> `, errors: 2, }, { code: ` foo }> `, errors: 1, }, ], } // For easier local testing if (!process.env.CI) { let only = [] let skipped = [] ;[...tests.valid, ...tests.invalid].forEach(t => { if (t.skip) { delete t.skip skipped.push(t) } if (t.only) { delete t.only only.push(t) } }) const predicate = t => { if (only.length > 0) { return only.indexOf(t) !== -1 } if (skipped.length > 0) { return skipped.indexOf(t) === -1 } return true } tests.valid = tests.valid.filter(predicate) tests.invalid = tests.invalid.filter(predicate) } ruleTester.run('avoid-unwrapped-text', avoidUnwrappedText, tests) })