@hint/hint-typescript-config
Version:
hint that that checks if the TypeScript configuration is valid.
311 lines (310 loc) • 10.6 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
const path = require("path");
const utils_tests_helpers_1 = require("@hint/utils-tests-helpers");
const utils_types_1 = require("@hint/utils-types");
const hintPath = (0, utils_tests_helpers_1.getHintPath)(__filename, true);
const paths = [
'es3',
'es5',
'es2015',
'es2016',
'esnext',
'extends',
'extends-overrides',
'no-target',
'no-target-extends',
'no-target-extends-target'
].reduce((final, version) => {
final[version] = path.join(__dirname, 'fixtures', 'target', version);
return final;
}, {});
const tests = [
{
browserslist: ['IE 8', 'IE 9', 'Edge 15', 'Edge 16', 'Chrome 63', 'Chrome 60', 'android 4.4.3-4.4.4', 'Safari 10.1', 'Safari 10.0'],
name: 'Configuration with "compilerOptions.target = es3" and old browsers should pass',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.es3
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: 'Configuration with "compilerOptions.target = es3" and modern browsers should fail',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.es3,
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: '"es3"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['IE 9', 'Edge 15', 'Chrome 63'],
name: 'Configuration with "compilerOptions.target = es5" and minimum browsers should pass',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.es5
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: 'Configuration with "compilerOptions.target = es2016" and modern browsers should pass',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.es2016
},
{
browserslist: ['IE 8', 'Edge 15', 'Chrome 63'],
name: 'Configuration with "compilerOptions.target = es2016" and old browsers should fail',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.es2016,
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES3". Current one is "ES2016"`,
position: { match: '"es2016"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: 'Configuration with "compilerOptions.target = esnext" and not very old browsers should fail',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.esnext,
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ESNext"`,
position: { match: '"esnext"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['IE 8', 'Edge 15', 'Chrome 63'],
name: 'Configuration with no "compilerOptions.target" and old browsers should pass',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['no-target']
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with no "compilerOptions.target" and modern browsers shouldn't pass`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['no-target'],
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: 'compilerOptions' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['IE 8', 'Edge 15', 'Chrome 63'],
name: 'Configuration with no "compilerOptions.target" in extended file and old browsers should pass',
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['no-target-extends']
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with no "compilerOptions.target" in extended file and modern browsers shouldn't pass`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['no-target-extends'],
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: 'compilerOptions' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with "compilerOptions.target" in extended file and modern browsers shouldn't pass`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['no-target-extends-target'],
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: '"../es3/tsconfig.json"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and modern browsers should pass`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.extends
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and target es3 should fail`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths['extends-overrides'],
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: '"es3"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and target es3 should fail if browserlist is found in package.json`,
overrides: {
'@hint/utils': {
findPackageRoot(dirname, fileToFind) {
if (fileToFind === 'package.json') {
return path.join(__dirname, 'fixtures', 'target', 'config-package-json');
}
throw new Error('Package not found');
}
}
},
path: paths['extends-overrides'],
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES2016". Current one is "ES3"`,
position: { match: '"es3"' },
severity: utils_types_1.Severity.warning
}
]
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and target es3 should pass if browserlist configuration is not found in package.json`,
overrides: {
'@hint/utils': {
findPackageRoot(dirname, fileToFind) {
if (fileToFind === 'package.json') {
return path.join(__dirname, 'fixtures', 'target', 'no-config-package-json');
}
throw new Error('Package not found');
}
}
},
path: paths['extends-overrides']
},
{
browserslist: ['Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and target es3 should pass if browserlist configuration is not found`,
overrides: {
'@hint/utils': {
findPackageRoot(dirname, fileToFind) {
throw new Error('Package not found');
}
}
},
path: paths['extends-overrides']
},
{
browserslist: ['IE 8', 'Edge 15', 'Chrome 63'],
name: `Configuration with extends pointing to ES2016 and old browsers should fail`,
overrides: {
'@hint/utils': {
findPackageRoot() {
return 'folder';
}
}
},
path: paths.extends,
reports: [
{
message: `Based on your browser configuration your "compilerOptions.target" should be "ES3". Current one is "ES2016"`,
position: { match: '"../es2016/tsconfig.json"' },
severity: utils_types_1.Severity.warning
}
]
}
];
tests.forEach((info) => {
const test = {
before: info.before,
name: info.name,
overrides: info.overrides,
path: info.path,
reports: info.reports
};
(0, utils_tests_helpers_1.testLocalHint)(hintPath, [test], {
browserslist: info.browserslist,
parsers: ['typescript-config'],
serial: true
});
});
;