diff --git a/build/webpack.e2e.config.js b/build/webpack.tests.config.js similarity index 64% rename from build/webpack.e2e.config.js rename to build/webpack.tests.config.js index 6e4f0842..24bcd146 100644 --- a/build/webpack.e2e.config.js +++ b/build/webpack.tests.config.js @@ -5,24 +5,27 @@ const base = require("./webpack.base.config"); // Test files are scattered through the whole project. Here we're searching // for them and generating entry file for webpack. -const e2eDir = jetpack.cwd("tests"); +const testsDir = jetpack.cwd("tests"); const tempDir = jetpack.cwd("temp"); -const entryFilePath = tempDir.path("e2e_entry.js"); +const entryFilePath = tempDir.path("testsInit.js"); -const entryFileContent = e2eDir +const testsImports = testsDir .find({ matching: "*.test.js" }) .reduce((fileContent, path) => { const normalizedPath = path.replace(/\\/g, "/"); - return `${fileContent}import "../tests/${normalizedPath}";\n`; + return `${fileContent}require("../tests/${normalizedPath}");\n`; }, ""); +let entryFileContent = testsDir.read('init.js') +entryFileContent = entryFileContent.replace('//TESTS', testsImports) + jetpack.write(entryFilePath, entryFileContent); module.exports = env => { return merge(base(env), { entry: entryFilePath, output: { - filename: "e2e.js", + filename: "tests.js", path: tempDir.path() } }); diff --git a/build/webpack.unit.config.js b/build/webpack.unit.config.js deleted file mode 100644 index c34a5a80..00000000 --- a/build/webpack.unit.config.js +++ /dev/null @@ -1,29 +0,0 @@ -const merge = require("webpack-merge"); -const jetpack = require("fs-jetpack"); -const base = require("./webpack.base.config"); - -// Test files are scattered through the whole project. Here we're searching -// for them and generating entry file for webpack. - -const srcDir = jetpack.cwd("src"); -const tempDir = jetpack.cwd("temp"); -const entryFilePath = tempDir.path("specs_entry.js"); - -const entryFileContent = srcDir - .find({ matching: "*.spec.js" }) - .reduce((fileContent, path) => { - const normalizedPath = path.replace(/\\/g, "/"); - return `${fileContent}import "../src/${normalizedPath}";\n`; - }, ""); - -jetpack.write(entryFilePath, entryFileContent); - -module.exports = env => { - return merge(base(env), { - entry: entryFilePath, - output: { - filename: "specs.js", - path: tempDir.path() - } - }); -}; diff --git a/package.json b/package.json index 09cac824..e4ab486b 100644 --- a/package.json +++ b/package.json @@ -102,8 +102,8 @@ }, "scripts": { "postinstall": "electron-builder install-app-deps", - "pretest": "webpack --config=build/webpack.app.config.js --env=test --display=none && webpack --config=build/webpack.e2e.config.js --env=test --display=none", - "test": "mocha temp/e2e.js --require @babel/core/lib --require source-map-support/register", + "pretest": "webpack --config=build/webpack.app.config.js --env=test --display=none && webpack --config=build/webpack.tests.config.js --env=test --display=none", + "test": "mocha temp/tests.js --require @babel/core/lib --require source-map-support/register", "start": "node build/start.js", "prebuild": "webpack --config=build/webpack.app.config.js --env=production", "build": "electron-builder", diff --git a/tests/utils.js b/tests/application.js similarity index 76% rename from tests/utils.js rename to tests/application.js index e95eeb9c..d7706f67 100644 --- a/tests/utils.js +++ b/tests/application.js @@ -1,7 +1,7 @@ import electron from "electron"; import { Application } from "spectron"; -const beforeEach = function() { +const startApplication = function() { this.timeout(30000); this.app = new Application({ path: electron, @@ -13,7 +13,7 @@ const beforeEach = function() { return this.app.start(); }; -const afterEach = function() { +const stopApplication = function() { this.timeout(30000); if (this.app && this.app.isRunning()) { return this.app.stop(); @@ -21,7 +21,7 @@ const afterEach = function() { return undefined; }; -export default { - beforeEach, - afterEach +export { + startApplication, + stopApplication }; diff --git a/tests/basic.test.js b/tests/basic.test.js deleted file mode 100644 index 9158546c..00000000 --- a/tests/basic.test.js +++ /dev/null @@ -1,12 +0,0 @@ -import { expect } from "chai"; -import testUtils from "./utils"; - -describe("application launch", () => { - before(testUtils.beforeEach); - after(testUtils.afterEach); - - it("index page loaded", async function() { - const { app } = this - await app.client.waitForExist('#index-window') - }); -}); diff --git a/tests/bigtableapi.test.js b/tests/bigtableapi.test.js index a84992d1..95bc79d5 100644 --- a/tests/bigtableapi.test.js +++ b/tests/bigtableapi.test.js @@ -2,20 +2,10 @@ const expect = (is) => { if(!is) throw new Error('expected not done'); } -import testUtils from "./utils"; - const {pool} = require('../src/background/mysql') const forBigTable = require('../src/background/forBigTable') describe("big table for check", () => { - before(testUtils.beforeEach); - after(testUtils.afterEach); - - it("runned", async function() { - const { app } = this - await app.client.waitForExist('#index-window') - }); - let sphinx; it("init", function() { diff --git a/tests/init.js b/tests/init.js new file mode 100644 index 00000000..6c387f54 --- /dev/null +++ b/tests/init.js @@ -0,0 +1,13 @@ +import {startApplication, stopApplication} from "../tests/application"; + +describe("application", () => { + before(startApplication); + after(stopApplication); + + it("check start", async function() { + const { app } = this + await app.client.waitForExist('#index-window') + }); + + //TESTS +}); diff --git a/tests/sphinx.test.js b/tests/sphinx.test.js index 94e71bdf..d81d68a6 100644 --- a/tests/sphinx.test.js +++ b/tests/sphinx.test.js @@ -1,18 +1,9 @@ import { expect } from "chai"; -import testUtils from "./utils"; const mysql = require('mysql') const config = require('../src/background/config') describe("sphinx", () => { - before(testUtils.beforeEach); - after(testUtils.afterEach); - - it("runned", async function() { - const { app } = this - await app.client.waitForExist('#index-window') - }); - let sphinx; it("init", function() {