[MM-39839] Changes for writing unit tests, some re-org (#1849)

* Move tests to individual folders

* Moved e2e tests to e2e folder, fixed lint issues

* Lint fix
This commit is contained in:
Devin Binnie 2021-11-04 11:29:32 -04:00 committed by GitHub
parent ba974dbf75
commit 0bd5a54c76
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
23 changed files with 76 additions and 81 deletions

View file

@ -39,7 +39,8 @@
}, },
{ {
"files": [ "files": [
"test/**/*" "e2e/**/*",
"src/**/*.test.js"
], ],
"env": { "env": {
"jest": true "jest": true
@ -57,14 +58,14 @@
{ {
"files": [ "files": [
"webpack.config.renderer.js", "webpack.config.renderer.js",
"test/specs/spellchecker_test.js", "e2e/specs/spellchecker_test.js",
"test/specs/app_test.js", "e2e/specs/app_test.js",
"test/specs/security_test.js", "e2e/specs/security_test.js",
"test/specs/permisson_test.js", "e2e/specs/permisson_test.js",
"test/specs/browser/index_test.js", "e2e/specs/browser/index_test.js",
"test/specs/browser/settings_test.js", "e2e/specs/browser/settings_test.js",
"test/modules/utils.js", "e2e/modules/utils.js",
"test/modules/environment.js", "e2e/modules/environment.js",
"CHANGELOG.md", "CHANGELOG.md",
"webpack.config.base.js", "webpack.config.base.js",
"babel.config.js", "babel.config.js",

122
.vscode/launch.json vendored
View file

@ -1,61 +1,61 @@
{ {
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
{ {
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Debug Main Process", "name": "Debug Main Process",
"cwd": "${workspaceRoot}", "cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"runtimeArgs": [ "runtimeArgs": [
"src", "src",
"--disable-dev-mode" "--disable-dev-mode"
], ],
"windows": { "windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
}, },
"program": "${workspaceRoot}/src/main.js", "program": "${workspaceRoot}/src/main.js",
"outFiles": [ "outFiles": [
"${workspaceRoot}/src/main_bundle.js" "${workspaceRoot}/src/main_bundle.js"
], ],
"sourceMaps": true, "sourceMaps": true,
"preLaunchTask": "Build sources" "preLaunchTask": "Build sources"
}, },
/* /*
{ {
"name": "Debug Renderer Process", "name": "Debug Renderer Process",
"type": "chrome", "type": "chrome",
"request": "launch", "request": "launch",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron", "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron",
"windows": { "windows": {
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd" "runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd"
}, },
"runtimeArgs": [ "runtimeArgs": [
"${workspaceRoot}/src", "${workspaceRoot}/src",
"--disable-dev-mode", "--disable-dev-mode",
"--remote-debugging-port=9222" "--remote-debugging-port=9222"
], ],
"webRoot": "${workspaceRoot}/src/browser", "webRoot": "${workspaceRoot}/src/browser",
"sourceMaps": true, "sourceMaps": true,
"preLaunchTask": "Build sources" "preLaunchTask": "Build sources"
}, },
*/ */
{ {
"type": "node", "type": "node",
"request": "launch", "request": "launch",
"name": "Mocha Tests", "name": "Mocha Tests",
"program": "${workspaceRoot}/node_modules/mocha/bin/_mocha", "program": "${workspaceRoot}/node_modules/mocha/bin/_mocha",
"args": [ "args": [
"-r", "-r",
"@babel/register", "@babel/register",
"--recursive", "--recursive",
"--timeout", "--timeout",
"999999", "999999",
"--colors", "--colors",
"${workspaceRoot}/test/specs" "${workspaceRoot}/e2e/specs"
], ],
"internalConsoleOptions": "openOnSessionStart", "internalConsoleOptions": "openOnSessionStart",
"preLaunchTask": "Build sources" "preLaunchTask": "Build sources"
} }
] ]
} }

View file

@ -98,7 +98,7 @@ Mattermost Desktop
│   ├── common/ - Common JavaScript modules for both Electron's processes. │   ├── common/ - Common JavaScript modules for both Electron's processes.
│   └── main/ - Implementation of Electron's main process. │   └── main/ - Implementation of Electron's main process.
│      └── menus/ - Application menu. │      └── menus/ - Application menu.
└── test/ - Automated tests. └── e2e/ - Automated tests.
   ├── modules/ - Scripts which are commonly used in tests.    ├── modules/ - Scripts which are commonly used in tests.
   └── specs/ - Test scripts.    └── specs/ - Test scripts.
``` ```

View file

@ -24,7 +24,7 @@ const electronBinaryPath = (() => {
const exeExtension = (process.platform === 'win32') ? '.exe' : ''; const exeExtension = (process.platform === 'win32') ? '.exe' : '';
return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension); return path.join(sourceRootDir, 'node_modules/electron/dist/electron' + exeExtension);
})(); })();
const userDataDir = path.join(sourceRootDir, 'test/testUserData/'); const userDataDir = path.join(sourceRootDir, 'e2e/testUserData/');
const configFilePath = path.join(userDataDir, 'config.json'); const configFilePath = path.join(userDataDir, 'config.json');
const boundsInfoPath = path.join(userDataDir, 'bounds-info.json'); const boundsInfoPath = path.join(userDataDir, 'bounds-info.json');
const mattermostURL = 'http://example.com/'; const mattermostURL = 'http://example.com/';

View file

@ -3,7 +3,6 @@
'use strict'; 'use strict';
import assert from 'assert'; import assert from 'assert';
import 'airbnb-js-shims/target/es2015';
import TrustedOriginsStore from 'main/trustedOrigins.ts'; import TrustedOriginsStore from 'main/trustedOrigins.ts';
import {BASIC_AUTH_PERMISSION} from 'common/permissions.ts'; import {BASIC_AUTH_PERMISSION} from 'common/permissions.ts';

View file

@ -1,5 +0,0 @@
// Copyright (c) 2016-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.
import './trusted_origins_test';
import './url_test';

View file

@ -7,6 +7,7 @@
const path = require('path'); const path = require('path');
const glob = require('glob');
const merge = require('webpack-merge'); const merge = require('webpack-merge');
const base = require('./webpack.config.base'); const base = require('./webpack.config.base');
@ -15,8 +16,8 @@ const WEBSERVER_PORT = 9001;
module.exports = merge(base, { module.exports = merge(base, {
entry: { entry: {
test: './test/unit/index.js', test: glob.sync('./src/**/*.test.js'),
e2e: './test/specs/index.js', e2e: './e2e/specs/index.js',
}, },
output: { output: {
path: path.resolve(__dirname, 'dist/tests'), path: path.resolve(__dirname, 'dist/tests'),
@ -29,7 +30,6 @@ module.exports = merge(base, {
}], }],
}, },
externals: { externals: {
puppeteer: 'require("puppeteer")',
fs: 'require("fs")', fs: 'require("fs")',
ws: 'require("ws")', ws: 'require("ws")',
child_process: 'require("child_process")', child_process: 'require("child_process")',