Skip to content

Commit

Permalink
fix(tests): simplify tests
Browse files Browse the repository at this point in the history
  • Loading branch information
DEgITx committed Jun 29, 2018
1 parent ac046d0 commit c3d62f5
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 72 deletions.
13 changes: 8 additions & 5 deletions build/webpack.e2e.config.js → build/webpack.tests.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
});
Expand Down
29 changes: 0 additions & 29 deletions build/webpack.unit.config.js

This file was deleted.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 5 additions & 5 deletions tests/utils.js → tests/application.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -13,15 +13,15 @@ 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();
}
return undefined;
};

export default {
beforeEach,
afterEach
export {
startApplication,
stopApplication
};
12 changes: 0 additions & 12 deletions tests/basic.test.js

This file was deleted.

10 changes: 0 additions & 10 deletions tests/bigtableapi.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
13 changes: 13 additions & 0 deletions tests/init.js
Original file line number Diff line number Diff line change
@@ -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
});
9 changes: 0 additions & 9 deletions tests/sphinx.test.js
Original file line number Diff line number Diff line change
@@ -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() {
Expand Down

0 comments on commit c3d62f5

Please sign in to comment.