aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLibravatar Ricardo Cino <ricardo@cino.io>2022-06-26 01:26:19 +0200
committerLibravatar GitHub <noreply@github.com>2022-06-25 23:26:19 +0000
commit465b5772763ccb8d4970d4c55e30a518abb7be3e (patch)
treee929e34910dbf6a3958cdc4de77dc1dcae93e7b0
parentchore: add more strict types in electron directory (#367) (diff)
downloadferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.gz
ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.tar.zst
ferdium-app-465b5772763ccb8d4970d4c55e30a518abb7be3e.zip
chore: moved tests to ./test directory (#366)
* chore: allow coverage to be generated from non-tested files
-rw-r--r--jest.config.js6
-rw-r--r--src/helpers/array-helpers.ts2
-rw-r--r--src/helpers/password-helpers.ts4
-rw-r--r--src/types.ts (renamed from @types/index.d.ts)1
-rw-r--r--test/features/utils/FeatureStore.test.js (renamed from src/features/utils/FeatureStore.test.js)8
-rw-r--r--test/helpers/array-helpers.test.ts15
-rw-r--r--test/helpers/url-helpers.test.ts (renamed from src/helpers/url-helpers.test.ts)42
-rw-r--r--test/jsUtils.test.ts (renamed from src/jsUtils.test.ts)2
-rw-r--r--test/themes/index.test.ts (renamed from src/themes/index.test.ts)6
-rw-r--r--tsconfig.json4
10 files changed, 61 insertions, 29 deletions
diff --git a/jest.config.js b/jest.config.js
index 264014997..964e4d4e6 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -20,7 +20,7 @@ module.exports = {
20 collectCoverage: true, 20 collectCoverage: true,
21 21
22 // An array of glob patterns indicating a set of files for which coverage information should be collected 22 // An array of glob patterns indicating a set of files for which coverage information should be collected
23 // collectCoverageFrom: undefined, 23 collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/internal-api'],
24 24
25 // The directory where Jest should output its coverage files 25 // The directory where Jest should output its coverage files
26 coverageDirectory: 'coverage', 26 coverageDirectory: 'coverage',
@@ -117,9 +117,7 @@ module.exports = {
117 // rootDir: undefined, 117 // rootDir: undefined,
118 118
119 // A list of paths to directories that Jest should use to search for files in 119 // A list of paths to directories that Jest should use to search for files in
120 roots: [ 120 roots: ['src/', 'test/'],
121 'src'
122 ],
123 121
124 // Allows you to use a custom runner instead of Jest's default test runner 122 // Allows you to use a custom runner instead of Jest's default test runner
125 // runner: "jest-runner", 123 // runner: "jest-runner",
diff --git a/src/helpers/array-helpers.ts b/src/helpers/array-helpers.ts
index 3f8806176..45ff932ba 100644
--- a/src/helpers/array-helpers.ts
+++ b/src/helpers/array-helpers.ts
@@ -1,4 +1,4 @@
1export const shuffleArray = (arr: any[]) => 1export const shuffleArray = (arr: any[]): any[] =>
2 arr 2 arr
3 .map(a => [Math.random(), a]) 3 .map(a => [Math.random(), a])
4 .sort((a, b) => a[0] - b[0]) 4 .sort((a, b) => a[0] - b[0])
diff --git a/src/helpers/password-helpers.ts b/src/helpers/password-helpers.ts
index 053321bbf..d5f2d0c49 100644
--- a/src/helpers/password-helpers.ts
+++ b/src/helpers/password-helpers.ts
@@ -1,10 +1,10 @@
1import { createHash, BinaryLike } from 'crypto'; 1import { createHash, BinaryLike } from 'crypto';
2 2
3export function hash(password: BinaryLike) { 3export function hash(password: BinaryLike): string {
4 return createHash('sha256').update(password).digest('base64'); 4 return createHash('sha256').update(password).digest('base64');
5} 5}
6 6
7export function scorePassword(password: string) { 7export function scorePassword(password: string): number {
8 let score = 0; 8 let score = 0;
9 if (!password) { 9 if (!password) {
10 return score; 10 return score;
diff --git a/@types/index.d.ts b/src/types.ts
index 015f1eb91..db8711cd3 100644
--- a/@types/index.d.ts
+++ b/src/types.ts
@@ -14,6 +14,7 @@ declare global {
14 } 14 }
15 } 15 }
16} 16}
17
17/** 18/**
18 * Workaround to make TS recognize this file as a module. 19 * Workaround to make TS recognize this file as a module.
19 * https://fettblog.eu/typescript-augmenting-global-lib-dom/ 20 * https://fettblog.eu/typescript-augmenting-global-lib-dom/
diff --git a/src/features/utils/FeatureStore.test.js b/test/features/utils/FeatureStore.test.js
index 1995431bd..d8d85bec1 100644
--- a/src/features/utils/FeatureStore.test.js
+++ b/test/features/utils/FeatureStore.test.js
@@ -1,9 +1,9 @@
1import PropTypes from 'prop-types'; 1import PropTypes from 'prop-types';
2import { observable } from 'mobx'; 2import { observable } from 'mobx';
3import { FeatureStore } from './FeatureStore'; 3import { FeatureStore } from '../../../src/features/utils/FeatureStore';
4import { createActionsFromDefinitions } from '../../actions/lib/actions'; 4import { createActionsFromDefinitions } from '../../../src/actions/lib/actions';
5import { createActionBindings } from './ActionBinding'; 5import { createActionBindings } from '../../../src/features/utils/ActionBinding';
6import { createReactions } from '../../stores/lib/Reaction'; 6import { createReactions } from '../../../src/stores/lib/Reaction';
7 7
8const actions = createActionsFromDefinitions( 8const actions = createActionsFromDefinitions(
9 { 9 {
diff --git a/test/helpers/array-helpers.test.ts b/test/helpers/array-helpers.test.ts
new file mode 100644
index 000000000..e8060c2c4
--- /dev/null
+++ b/test/helpers/array-helpers.test.ts
@@ -0,0 +1,15 @@
1import { shuffleArray } from '../../src/helpers/array-helpers';
2
3describe('array_helpers', () => {
4 it('isValidExternalURL', () => {
5 const originalArray = ['a', 'b', 'c'];
6 const shuffledArray = shuffleArray(originalArray);
7
8 // Expect the arrays to not be exactly the same
9 expect(shuffledArray).not.toEqual(originalArray);
10
11 // Expect the arrays to be exactly the same
12 // when both are sorted alphabetically
13 expect(shuffledArray.sort()).toEqual(originalArray.sort());
14 });
15});
diff --git a/src/helpers/url-helpers.test.ts b/test/helpers/url-helpers.test.ts
index 5af3025e9..9ef06b905 100644
--- a/src/helpers/url-helpers.test.ts
+++ b/test/helpers/url-helpers.test.ts
@@ -1,4 +1,4 @@
1import * as url_helpers from './url-helpers' 1import * as url_helpers from '../../src/helpers/url-helpers';
2 2
3describe('url_helpers', () => { 3describe('url_helpers', () => {
4 describe('isValidExternalURL', () => { 4 describe('isValidExternalURL', () => {
@@ -38,7 +38,9 @@ describe('url_helpers', () => {
38 // Note: not testing the invalid string urls - since the URL ctor itself will raise an error 38 // Note: not testing the invalid string urls - since the URL ctor itself will raise an error
39 39
40 it('returns false for invalid url', () => { 40 it('returns false for invalid url', () => {
41 const result = url_helpers.isValidExternalURL(new URL('shttps://google')); 41 const result = url_helpers.isValidExternalURL(
42 new URL('shttps://google'),
43 );
42 expect(result).toBe(false); 44 expect(result).toBe(false);
43 }); 45 });
44 46
@@ -48,7 +50,9 @@ describe('url_helpers', () => {
48 }); 50 });
49 51
50 it('returns true for valid https url', () => { 52 it('returns true for valid https url', () => {
51 const result = url_helpers.isValidExternalURL(new URL('https://google')); 53 const result = url_helpers.isValidExternalURL(
54 new URL('https://google'),
55 );
52 expect(result).toBe(true); 56 expect(result).toBe(true);
53 }); 57 });
54 }); 58 });
@@ -71,21 +75,34 @@ describe('url_helpers', () => {
71 }); 75 });
72 76
73 it('handles string starting with http://', () => { 77 it('handles string starting with http://', () => {
74 expect(url_helpers.fixUrl('http://some/random/url')).toEqual('http://some/random/url'); 78 expect(url_helpers.fixUrl('http://some/random/url')).toEqual(
75 expect(url_helpers.fixUrl('http://some//random//url')).toEqual('http://some/random/url'); 79 'http://some/random/url',
76 80 );
77 const gmailEmbeddedUrl = 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail'; 81 expect(url_helpers.fixUrl('http://some//random//url')).toEqual(
82 'http://some/random/url',
83 );
84
85 const gmailEmbeddedUrl =
86 'https://www.google.com/url?q=https://github.com/ferdium/ferdium-app/issues/87&source=gmail';
78 expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string 87 expect(url_helpers.fixUrl(gmailEmbeddedUrl)).toEqual(gmailEmbeddedUrl); // it should NOT remove the double-slash from the embedded url in the query string
79 }); 88 });
80 89
81 it('handles string starting with https://', () => { 90 it('handles string starting with https://', () => {
82 expect(url_helpers.fixUrl('https://some/random/url')).toEqual('https://some/random/url'); 91 expect(url_helpers.fixUrl('https://some/random/url')).toEqual(
83 expect(url_helpers.fixUrl('https://some//random//url')).toEqual('https://some/random/url'); 92 'https://some/random/url',
93 );
94 expect(url_helpers.fixUrl('https://some//random//url')).toEqual(
95 'https://some/random/url',
96 );
84 }); 97 });
85 98
86 it('handles string starting with file://', () => { 99 it('handles string starting with file://', () => {
87 expect(url_helpers.fixUrl('file://some/random/url')).toEqual('file://some/random/url'); 100 expect(url_helpers.fixUrl('file://some/random/url')).toEqual(
88 expect(url_helpers.fixUrl('file://some//random//url')).toEqual('file://some/random/url'); 101 'file://some/random/url',
102 );
103 expect(url_helpers.fixUrl('file://some//random//url')).toEqual(
104 'file://some/random/url',
105 );
89 }); 106 });
90 }); 107 });
91 108
@@ -111,7 +128,8 @@ describe('url_helpers', () => {
111 }); 128 });
112 129
113 it('returns true for valid file url', () => { 130 it('returns true for valid file url', () => {
114 const fileName = process.platform === 'win32' ? 'file:///c:\\' : 'file:///'; 131 const fileName =
132 process.platform === 'win32' ? 'file:///c:\\' : 'file:///';
115 const result = url_helpers.isValidFileUrl(fileName); 133 const result = url_helpers.isValidFileUrl(fileName);
116 expect(result).toBe(true); 134 expect(result).toBe(true);
117 }); 135 });
diff --git a/src/jsUtils.test.ts b/test/jsUtils.test.ts
index 34cd8f098..8ef69b46f 100644
--- a/src/jsUtils.test.ts
+++ b/test/jsUtils.test.ts
@@ -1,4 +1,4 @@
1import * as jsUtils from './jsUtils' 1import * as jsUtils from '../src/jsUtils';
2 2
3describe('jsUtils', () => { 3describe('jsUtils', () => {
4 describe('ifUndefinedString', () => { 4 describe('ifUndefinedString', () => {
diff --git a/src/themes/index.test.ts b/test/themes/index.test.ts
index e9f0f391b..387a296a8 100644
--- a/src/themes/index.test.ts
+++ b/test/themes/index.test.ts
@@ -1,6 +1,6 @@
1import makeDefaultThemeConfig from './default'; 1import makeDefaultThemeConfig from '../../src/themes/default';
2import makeDarkThemeConfig from './dark'; 2import makeDarkThemeConfig from '../../src/themes/dark';
3import { theme, ThemeType } from '.'; 3import { theme, ThemeType } from '../../src/themes';
4 4
5describe('Load theme', () => { 5describe('Load theme', () => {
6 it('loads default theme', () => { 6 it('loads default theme', () => {
diff --git a/tsconfig.json b/tsconfig.json
index c600df5cf..3e7ffc854 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -12,7 +12,6 @@
12 "module": "CommonJS", 12 "module": "CommonJS",
13 "jsx": "react-jsx", 13 "jsx": "react-jsx",
14 "typeRoots": [ 14 "typeRoots": [
15 "@types",
16 "node_modules/@types" 15 "node_modules/@types"
17 ], 16 ],
18 "moduleResolution": "node", 17 "moduleResolution": "node",
@@ -46,6 +45,7 @@
46 }, 45 },
47 "include": [ 46 "include": [
48 "src", 47 "src",
49 "scripts" 48 "scripts",
49 "test",
50 ], 50 ],
51} 51}