Repository: darkreader/darkreader
Pull request #3057 (2020-07-09 14:19:12)

Run all tests
- Make "npm test" run all tests.
- Move tests into separate folders.


Patch:
diff --git a/package.json b/package.json
index c01a79c4..b65f6657 100644
--- a/package.json
+++ b/package.json
@@ -10,11 +10,13 @@
     "debug-watch": "node tasks/build.js --debug --watch",
     "prepublishOnly": "npm test && npm run api",
     "release": "npm test && node tasks/build.js --release",
-    "test": "npm run test:config",
-    "test:config": "jest --config=tests/jest.config.js",
-    "test:config:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/jest.config.js --runInBand --no-cache --watch",
+    "test": "npm run test:config && npm run test:inject && npm run test:utils",
+    "test:config": "jest --config=tests/config/jest.config.js",
+    "test:config:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/config/jest.config.js --runInBand --no-cache --watch",
     "test:inject": "jest --config=tests/inject/jest.config.js",
-    "test:inject:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/inject/jest.config.js --runInBand --no-cache --watch"
+    "test:inject:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/inject/jest.config.js --runInBand --no-cache --watch",
+    "test:utils": "jest --config=tests/utils/jest.config.js",
+    "test:utils:debug": "node --inspect-brk ./node_modules/jest/bin/jest --config=tests/utils/jest.config.js --runInBand --no-cache --watch"
   },
   "main": "darkreader.js",
   "repository": {


Test patch:
diff --git a/tests/config.tests.ts b/tests/config/config.tests.ts
similarity index 91%
rename from tests/config.tests.ts
rename to tests/config/config.tests.ts
index 36aa7548..0d4aba2e 100644
--- a/tests/config.tests.ts
+++ b/tests/config/config.tests.ts
@@ -1,14 +1,14 @@
 import {readFile} from 'fs';
 import {resolve as resolvePath} from 'path';
-import {compareURLPatterns} from '../src/utils/url';
-import {parseArray, formatArray, getTextDiffIndex, getTextPositionMessage} from '../src/utils/text';
-import {parseInversionFixes, formatInversionFixes} from '../src/generators/css-filter';
-import {parseDynamicThemeFixes, formatDynamicThemeFixes} from '../src/generators/dynamic-theme';
-import {parseStaticThemes, formatStaticThemes} from '../src/generators/static-theme';
+import {compareURLPatterns} from '../../src/utils/url';
+import {parseArray, formatArray, getTextDiffIndex, getTextPositionMessage} from '../../src/utils/text';
+import {parseInversionFixes, formatInversionFixes} from '../../src/generators/css-filter';
+import {parseDynamicThemeFixes, formatDynamicThemeFixes} from '../../src/generators/dynamic-theme';
+import {parseStaticThemes, formatStaticThemes} from '../../src/generators/static-theme';
 
 function readConfig(fileName) {
     return new Promise<string>((resolve, reject) => {
-        readFile(resolvePath(__dirname, '../src/config/', fileName), {encoding: 'utf-8'}, (err, data) => {
+        readFile(resolvePath(__dirname, '../../src/config/', fileName), {encoding: 'utf-8'}, (err, data) => {
             if (err) {
                 reject(err);
                 return;
diff --git a/tests/config/jest.config.js b/tests/config/jest.config.js
new file mode 100644
index 00000000..1d1d1e63
--- /dev/null
+++ b/tests/config/jest.config.js
@@ -0,0 +1,26 @@
+module.exports = {
+    verbose: true,
+    testEnvironment: 'node',
+    transform: {
+        '^.+\\.ts(x?)$': 'ts-jest'
+    },
+    testRegex: 'tests/config/.*\\.tests\\.ts(x?)$',
+    moduleFileExtensions: [
+        'ts',
+        'tsx',
+        'js'
+    ],
+    collectCoverage: false,
+    coverageDirectory: 'coverage',
+    collectCoverageFrom: [
+        'src/**/*.{ts,tsx}'
+    ],
+    coveragePathIgnorePatterns: [
+        '^.+\\.d\\.ts$'
+    ],
+    globals: {
+        'ts-jest': {
+            tsConfig: './tests/config/tsconfig.json'
+        }
+    }
+};
diff --git a/tests/locales.tests.ts b/tests/config/locales.tests.ts
similarity index 92%
rename from tests/locales.tests.ts
rename to tests/config/locales.tests.ts
index dbb9fad6..7bb32355 100644
--- a/tests/locales.tests.ts
+++ b/tests/config/locales.tests.ts
@@ -15,7 +15,7 @@ function readDir(dir) {
 
 function readLocale(name) {
     return new Promise<string>((resolve, reject) => {
-        fsReadFile(resolvePath(__dirname, '../src/_locales/', name), {encoding: 'utf-8'}, (err, data) => {
+        fsReadFile(resolvePath(__dirname, '../../src/_locales/', name), {encoding: 'utf-8'}, (err, data) => {
             if (err) {
                 reject(err);
                 return;
@@ -26,7 +26,7 @@ function readLocale(name) {
 }
 
 test('Locales', async () => {
-    const files = await readDir('../src/_locales');
+    const files = await readDir('../../src/_locales');
     const enLocale = await readLocale('en.config');
     const enLines = enLocale.split('\n');
     const locales: string[] = [];
diff --git a/tests/tsconfig.json b/tests/config/tsconfig.json
similarity index 80%
rename from tests/tsconfig.json
rename to tests/config/tsconfig.json
index 2d65ac96..8577f299 100644
--- a/tests/tsconfig.json
+++ b/tests/config/tsconfig.json
@@ -1,5 +1,5 @@
 {
-    "extends": "../src/tsconfig",
+    "extends": "../../src/tsconfig",
     "compilerOptions": {
         "module": "commonjs",
         "outDir": "",
diff --git a/tests/color.tests.ts b/tests/utils/color.tests.ts
similarity index 99%
rename from tests/color.tests.ts
rename to tests/utils/color.tests.ts
index 1a741aad..01813f1d 100644
--- a/tests/color.tests.ts
+++ b/tests/utils/color.tests.ts
@@ -1,4 +1,4 @@
-import {parse, hslToRGB, rgbToHSL, rgbToString, rgbToHexString, hslToString, HSLA} from '../src/utils/color';
+import {parse, hslToRGB, rgbToHSL, rgbToString, rgbToHexString, hslToString, HSLA} from '../../src/utils/color';
 
 test('Color parsing', () => {
     expect(parse('rgb(255,0,153)')).toEqual({r: 255, g: 0, b: 153, a: 1});
diff --git a/tests/jest.config.js b/tests/utils/jest.config.js
similarity index 81%
rename from tests/jest.config.js
rename to tests/utils/jest.config.js
index 5482690a..8f5db0f8 100644
--- a/tests/jest.config.js
+++ b/tests/utils/jest.config.js
@@ -4,7 +4,7 @@ module.exports = {
     transform: {
         '^.+\\.ts(x?)$': 'ts-jest'
     },
-    testRegex: 'tests/[^/]*\\.tests\\.ts(x?)$',
+    testRegex: 'tests/utils/.*\\.tests\\.ts(x?)$',
     moduleFileExtensions: [
         'ts',
         'tsx',
@@ -20,7 +20,7 @@ module.exports = {
     ],
     globals: {
         'ts-jest': {
-            tsConfig: './tests/tsconfig.json'
+            tsConfig: './tests/utils/tsconfig.json'
         }
     }
 };
diff --git a/tests/time.tests.ts b/tests/utils/time.tests.ts
similarity index 98%
rename from tests/time.tests.ts
rename to tests/utils/time.tests.ts
index ff1c21bc..84d4a44d 100644
--- a/tests/time.tests.ts
+++ b/tests/utils/time.tests.ts
@@ -1,4 +1,4 @@
-import {isInTimeInterval, isNightAtLocation, parseTime, getDuration} from '../src/utils/time';
+import {isInTimeInterval, isNightAtLocation, parseTime, getDuration} from '../../src/utils/time';
 
 test('Time interval', () => {
     expect(isInTimeInterval(new Date(2018, 11, 4, 10), '9:00', '12:00')).toBe(true);
diff --git a/tests/utils/tsconfig.json b/tests/utils/tsconfig.json
new file mode 100644
index 00000000..8577f299
--- /dev/null
+++ b/tests/utils/tsconfig.json
@@ -0,0 +1,11 @@
+{
+    "extends": "../../src/tsconfig",
+    "compilerOptions": {
+        "module": "commonjs",
+        "outDir": "",
+        "types": [
+            "jest",
+            "node"
+        ]
+    }
+}
diff --git a/tests/url.tests.ts b/tests/utils/url.tests.ts
similarity index 98%
rename from tests/url.tests.ts
rename to tests/utils/url.tests.ts
index 686de5a0..bc627c9e 100644
--- a/tests/url.tests.ts
+++ b/tests/utils/url.tests.ts
@@ -1,5 +1,5 @@
-import {isURLEnabled, isURLMatched, isPDF} from '../src/utils/url';
-import {UserSettings} from '../src/definitions';
+import {isURLEnabled, isURLMatched, isPDF} from '../../src/utils/url';
+import {UserSettings} from '../../src/definitions';
 
 test('URL is enabled', () => {
     // Not invert listed
@@ -132,7 +132,7 @@ test('URL is enabled', () => {
     )).toBe(false);
     expect(isPDF(
         'https://upload.wikimedia.org/wikipedia/commons/5/56/ExtIPA_chart_(2015).pdf'
-    )).toBe(true);  
+    )).toBe(true);
 
     // IPV6 Testing
     expect(isURLEnabled(