Unverified Commit e63f7d71 authored by Tasso Evangelista's avatar Tasso Evangelista Committed by GitHub

Merge pull request #1046 from RocketChat/chore/broken-tests

[CHORE] Fix broken tests
parents de3daf90 bad505c4
.DS_Store
Thumbs.db
*.log
*.autogenerated
/node_modules
/package-lock.json
......
language: node_js
node_js: 8
node_js: 10
cache:
yarn: true
directories:
......@@ -37,6 +37,8 @@ before_install:
install:
- yarn
- yarn test
- yarn e2e
script:
- if [[ "$TRAVIS_PULL_REQUEST" != "false" ]]; then export CSC_IDENTITY_AUTO_DISCOVERY=false; fi
......
image: Visual Studio 2017
environment:
nodejs_version: "8"
nodejs_version: "10"
platform:
- x64
skip_tags: true
......@@ -21,7 +21,8 @@ install:
- ps: Install-Product node $env:nodejs_version $env:platform
- set CI=true
- yarn
- yarn list
- yarn test
- yarn e2e
build_script:
- yarn release
......
......@@ -13,7 +13,8 @@
"url": "https://github.com/RocketChat/Rocket.Chat.Electron.git"
},
"scripts": {
"postinstall": "electron-builder install-app-deps",
"postinstall": "electron-builder install-app-deps",
"postremove": "electron-builder install-app-deps",
"start": "gulp start",
"build": "gulp build-app",
"changelog": "conventional-changelog --config .github/changelog.js -i HISTORY.md -s",
......@@ -22,12 +23,16 @@
"release-mas-dev": "build --publish never --mac mas-dev --c.mac.provisioningProfile=Development.provisionprofile",
"lint": "eslint src",
"pretest": "gulp build-unit-tests --env=test",
"test-main": "electron-mocha --require source-map-support/register app/main.specs.js",
"test-renderer": "electron-mocha --require source-map-support/register --renderer app/renderer.specs.js",
"test-main": "xvfb-maybe electron-mocha --require source-map-support/register app/main.specs.js",
"test-renderer": "xvfb-maybe electron-mocha --require source-map-support/register --renderer app/renderer.specs.js",
"test": "npm-run-all test-main test-renderer",
"coverage": "npm test -- -R scripts/istanbul-reporter",
"precoverage": "gulp build-coverage-tests --env=test",
"coverage-main": "xvfb-maybe electron-mocha --require source-map-support/register --reporter tasks/coverage-reporter app/main.specs.js",
"coverage-renderer": "xvfb-maybe electron-mocha --require source-map-support/register --reporter tasks/coverage-reporter app/renderer.specs.js",
"coverage": "npm-run-all coverage-main coverage-renderer",
"postcoverage": "node tasks/coverage-reporter",
"pree2e": "gulp build-e2e-tests --env=test",
"e2e": "mocha app/e2e.js.autogenerated --require source-map-support/register"
"e2e": "xvfb-maybe mocha --require source-map-support/register app/e2e.js"
},
"dependencies": {
"@paulcbetts/system-idle-time": "^1.0.4",
......@@ -54,10 +59,10 @@
"gulp-rename": "^1.4.0",
"gulp-util": "^3.0.8",
"gulp-watch": "^5.0.1",
"istanbul": "^0.4.5",
"minimist": "^1.2.0",
"mocha": "^5.2.0",
"npm-run-all": "^4.1.3",
"nyc": "^13.1.0",
"rollup": "^0.67.3",
"rollup-plugin-commonjs": "^9.2.0",
"rollup-plugin-istanbul": "^2.0.1",
......@@ -65,7 +70,8 @@
"rollup-plugin-node-resolve": "^3.4.0",
"run-sequence": "^2.2.1",
"sinon": "^7.1.1",
"spectron": "^5.0.0"
"spectron": "^5.0.0",
"xvfb-maybe": "^0.2.1"
},
"devEngines": {
"node": ">=8.12.x",
......
var istanbul = require('istanbul');
module.exports = function (runner, options) {
mocha.reporters.Base.call(this, runner);
var reporterOpts = { dir: 'coverage' },
reporters = ['text-summary', 'html'];
options = options || {};
if (options.reporters) reporters = options.reporters.split(',');
if (process.env.ISTANBUL_REPORTERS) reporters = process.env.ISTANBUL_REPORTERS.split(',');
if (options.reportDir) reporterOpts.dir = options.reportDir;
if (process.env.ISTANBUL_REPORT_DIR) reporterOpts.dir = process.env.ISTANBUL_REPORT_DIR;
runner.on('end', function(){
var cov = global.__coverage__ || {},
collector = new istanbul.Collector();
collector.add(cov);
reporters.forEach(function(reporter) {
istanbul.Report.create(reporter, reporterOpts).writeReport(collector, true);
});
});
};
......@@ -18,6 +18,7 @@ const getRendererWindow = async() => {
return rendererWindow;
};
/* istanbul ignore next */
const renderInWindow = async(style) => {
const statusColors = {
offline: null,
......
......@@ -19,6 +19,7 @@ const createTemplate = ({
submenu: [
...(process.platform === 'darwin' ? [
{
id: 'about',
label: i18n.__('About %s', appName),
click: () => events.emit('about'),
},
......
......@@ -8,7 +8,7 @@ describe('application', function() {
after(stopApp);
it('shows the main window', async function() {
expect(await app.browserWindow.getTitle()).to.be.equals(appManifest.productName);
expect(await app.browserWindow.isVisible()).to.be.true;
expect(await app.browserWindow.getTitle()).to.be.equal(appManifest.productName);
});
});
import path from 'path';
import electron from 'electron';
import { Application } from 'spectron';
......@@ -16,7 +15,7 @@ export async function startApp() {
app = new Application({
path: electron,
cwd: process.cwd(),
args: [path.join(__dirname, '..')],
args: [process.cwd()],
quitTimeout: 5000,
startTimeout: 5000,
waitTimeout: 5000,
......@@ -25,6 +24,13 @@ export async function startApp() {
await app.start();
await app.client.waitUntilWindowLoaded();
for (let i = 0; i < (await app.client.windowHandles()).value.length; ++i) {
await app.client.windowByIndex(i);
if (await app.browserWindow.isVisible()) {
break;
}
}
logFetchInterval = setInterval(fetchLogs, 100);
}
......
const gulp = require('gulp');
const jetpack = require('fs-jetpack');
const bundle = require('./bundle');
const istanbul = require('rollup-plugin-istanbul');
const createEntryFile = async(srcDir, matching, outputDir, entryFileName, rollupOptions) => {
const entryFileContent = srcDir.find('.', { matching })
.map((path) => `import './${ path.replace(/\\/g, '/') }';`)
.join('\n');
srcDir.write(entryFileName, entryFileContent);
await bundle(srcDir.path(entryFileName), outputDir.path(entryFileName), rollupOptions);
srcDir.remove(entryFileName);
};
gulp.task('build-unit-tests', ['environment'], () => {
const rollupOptions = {
rollupPlugins: [
istanbul({
exclude: ['**/*.spec.js', '**/*.specs.js'],
sourcemap: true,
}),
],
};
gulp.task('build-unit-tests', ['build-app'], async() => {
await bundle.many('src', 'background/*.spec.js', 'app/main.specs.js');
await bundle.many('src', ['*.spec.js', '!background/*.spec.js'], 'app/renderer.specs.js');
});
return Promise.all([
createEntryFile(jetpack.cwd('src'), 'background/*.spec.js',
jetpack.cwd('app'), 'main.specs.js', rollupOptions),
createEntryFile(jetpack.cwd('src'), ['*.spec.js', '!background/*.spec.js'],
jetpack.cwd('app'), 'renderer.specs.js', rollupOptions),
]);
gulp.task('build-coverage-tests', ['build-app'], async() => {
await bundle.many('src', 'background/*.spec.js', 'app/main.specs.js', { coverage: true });
await bundle.many('src', ['*.spec.js', '!background/*.spec.js'], 'app/renderer.specs.js', { coverage: true });
});
gulp.task('build-e2e-tests', ['build-app'], () => createEntryFile(
jetpack.cwd('src'), '*.e2e.js',
jetpack.cwd('app'), 'e2e.js.autogenerated'
));
gulp.task('build-e2e-tests', ['build-app'], async() => {
await bundle.many('src', '*.e2e.js', 'app/e2e.js');
});
const path = require('path');
const builtinModules = require('builtin-modules');
const appManifest = require('../package.json');
const jetpack = require('fs-jetpack');
const path = require('path');
const { rollup } = require('rollup');
const commonjs = require('rollup-plugin-commonjs');
const istanbul = require('rollup-plugin-istanbul');
const json = require('rollup-plugin-json');
const nodeResolve = require('rollup-plugin-node-resolve');
const commonjs = require('rollup-plugin-commonjs');
const appManifest = require('../package.json');
const cached = {};
module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
const bundle = async(src, dest, { coverage = false, rollupPlugins = [] } = {}) => {
const inputOptions = {
input: src,
external: [
......@@ -20,6 +22,12 @@ module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
cache: cached[src],
plugins: [
...rollupPlugins,
...(coverage ? [
istanbul({
exclude: ['**/*.spec.js', '**/*.specs.js'],
sourcemap: true,
}),
] : []),
json(),
nodeResolve(),
commonjs(),
......@@ -39,3 +47,19 @@ module.exports = async(src, dest, { rollupPlugins = [] } = {}) => {
cached[src] = bundle;
await bundle.write(outputOptions);
};
const bundleMany = async(srcDirPath, matching, dest, options) => {
const srcDir = jetpack.cwd(srcDirPath);
const src = srcDir.path(path.basename(dest));
const entryFileContent = (await srcDir.findAsync({ matching }))
.map((path) => `import './${ path.replace(/\\/g, '/') }';`)
.join('\n');
await jetpack.writeAsync(src, entryFileContent);
await bundle(src, dest, options);
await jetpack.removeAsync(src);
};
module.exports = bundle;
module.exports.many = bundleMany;
const { reporters: { Base } } = require('mocha');
const NYC = require('nyc');
module.exports = function(runner, options = {}) {
Base.call(this, runner, options);
runner.on('end', () => {
const nyc = new NYC({ include: 'src/' });
nyc.createTempDirectory();
nyc.addAllFiles();
});
};
if (require.main === module) {
const nyc = new NYC({
include: 'src/',
reporter: ['text-summary', 'html'],
reportDir: 'coverage',
});
nyc.report();
nyc.cleanup();
}
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment