You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@senssoft.apache.org by rf...@apache.org on 2018/06/07 17:10:54 UTC
[2/3] incubator-senssoft-useralejs git commit: Switched to using test
utils (fixes broken tests)
Switched to using test utils (fixes broken tests)
Project: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/commit/3a5eac66
Tree: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/tree/3a5eac66
Diff: http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/diff/3a5eac66
Branch: refs/heads/SENSSOFT-192
Commit: 3a5eac66d5e460fc785d0544deae663f0d563d7a
Parents: 1a1cb11
Author: Rob Foley <rg...@draper.com>
Authored: Thu Jun 7 12:42:26 2018 -0400
Committer: Rob Foley <rg...@draper.com>
Committed: Thu Jun 7 13:09:21 2018 -0400
----------------------------------------------------------------------
test/getInitialSettings_spec.js | 55 +++++++-----------
test/main_spec.js | 110 ++++++++++++++++-------------------
2 files changed, 70 insertions(+), 95 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/3a5eac66/test/getInitialSettings_spec.js
----------------------------------------------------------------------
diff --git a/test/getInitialSettings_spec.js b/test/getInitialSettings_spec.js
index 9705409..2063332 100644
--- a/test/getInitialSettings_spec.js
+++ b/test/getInitialSettings_spec.js
@@ -18,6 +18,7 @@ import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import { createEnv } from './testUtils';
import { timeStampScale } from '../src/getInitialSettings.js';
import { version } from '../package.json';
@@ -67,47 +68,31 @@ describe('getInitialSettings', () => {
it('fetches all settings from a script tag', (done) => {
const html = fs.readFileSync(__dirname + '/getInitialSettings_fetchAll.html');
- jsdom.env({
- html : html,
- url : 'file://' + __dirname + '/getInitialSettings_fetchAll.html',
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
- done : (err, window) => {
- const config = window.userale.options();
- expect(config).to.have.property('autostart', true);
- expect(config).to.have.property('url', 'http://test.com');
- expect(config).to.have.property('transmitInterval', 100);
- expect(config).to.have.property('logCountThreshold', 10);
- expect(config).to.have.property('userId', 'testuser');
- expect(config).to.have.property('version', '1.0.0');
- expect(config).to.have.property('logDetails', false);
- expect(config).to.have.property('resolution', 100);
- expect(config).to.have.property('toolName', 'testtool');
- window.close();
- done();
- }
+ createEnv(html, (err, window) => {
+ const config = window.userale.options();
+ expect(config).to.have.property('autostart', true);
+ expect(config).to.have.property('url', 'http://test.com');
+ expect(config).to.have.property('transmitInterval', 100);
+ expect(config).to.have.property('logCountThreshold', 10);
+ expect(config).to.have.property('userId', 'testuser');
+ expect(config).to.have.property('version', '1.0.0');
+ expect(config).to.have.property('logDetails', false);
+ expect(config).to.have.property('resolution', 100);
+ expect(config).to.have.property('toolName', 'testtool');
+ window.close();
+ done();
});
});
it('grabs user id from params', (done) => {
const html = fs.readFileSync(__dirname + '/getInitialSettings_userParam.html');
- jsdom.env({
- html : html,
- url : 'file://' + __dirname + '/getInitialSettings_userParam.html?user=testuser',
- features : {
- FetchExternalResources : ['script'],
- ProcessExternalResources : ['script']
- },
- done : (err, window) => {
- const config = window.userale.options();
- expect(config.userId).to.equal('testuser');
- window.close();
- done();
- }
- });
+ createEnv(html, (err, window) => {
+ const config = window.userale.options();
+ expect(config.userId).to.equal('testuser');
+ window.close();
+ done();
+ }, { url : 'http://localhost:8080?user=testuser' });
});
});
});
http://git-wip-us.apache.org/repos/asf/incubator-senssoft-useralejs/blob/3a5eac66/test/main_spec.js
----------------------------------------------------------------------
diff --git a/test/main_spec.js b/test/main_spec.js
index 950ce75..26f9f59 100644
--- a/test/main_spec.js
+++ b/test/main_spec.js
@@ -18,6 +18,8 @@ import { expect } from 'chai';
import jsdom from 'jsdom';
import fs from 'fs';
+import { createEnv } from './testUtils';
+
describe('Userale API', () => {
const url = 'file://' + __dirname + '/main.html';
const html = fs.readFileSync(__dirname + '/main.html');
@@ -27,84 +29,72 @@ describe('Userale API', () => {
};
it('provides configs', (done) => {
- jsdom.env({
- html, url, features,
- done : (err, window) => {
- const config = window.userale.options();
- expect(config).to.be.an('object');
- expect(config).to.have.all.keys([
- 'on',
- 'useraleVersion',
- 'autostart',
- 'url',
- 'transmitInterval',
- 'logCountThreshold',
- 'userId',
- 'version',
- 'logDetails',
- 'resolution',
- 'toolName',
- 'userFromParams',
- 'time',
- ]);
- window.close();
- done();
- }
+ createEnv(html, (err, window) => {
+ const config = window.userale.options();
+ expect(config).to.be.an('object');
+ expect(config).to.have.all.keys([
+ 'on',
+ 'useraleVersion',
+ 'autostart',
+ 'url',
+ 'transmitInterval',
+ 'logCountThreshold',
+ 'userId',
+ 'version',
+ 'logDetails',
+ 'resolution',
+ 'toolName',
+ 'userFromParams',
+ 'time',
+ ]);
+ window.close();
+ done();
});
});
it('edits configs', (done) => {
- jsdom.env({
- html, url, features,
- done : (err, window) => {
- const config = window.userale.options();
- const interval = config.transmitInterval;
- window.userale.options({
- transmitInterval : interval + 10
- });
- const newConfig = window.userale.options();
+ createEnv(html, (err, window) => {
+ const config = window.userale.options();
+ const interval = config.transmitInterval;
+ window.userale.options({
+ transmitInterval : interval + 10
+ });
+ const newConfig = window.userale.options();
- expect(newConfig.transmitInterval).to.equal(interval + 10);
- window.close();
- done();
- }
+ expect(newConfig.transmitInterval).to.equal(interval + 10);
+ window.close();
+ done();
});
});
it('starts + stops', (done) => {
- jsdom.env({
- html, url, features,
- done : (err, window) => {
- setTimeout(() => {
- const { userale } = window;
- expect(userale.options().on).to.equal(true);
+ createEnv(html, (err, window) => {
+ setTimeout(() => {
+ const { userale } = window;
+ expect(userale.options().on).to.equal(true);
- userale.stop();
- expect(userale.options().on).to.equal(false);
+ userale.stop();
+ expect(userale.options().on).to.equal(false);
- userale.start();
- expect(userale.options().on).to.equal(true);
+ userale.start();
+ expect(userale.options().on).to.equal(true);
- window.close();
- done();
- }, 200);
- }
+ window.close();
+ done();
+ }, 200);
});
});
it('sends custom logs', (done) => {
- jsdom.env({
- html, url, features,
- done: (err, window) => {
- const { userale } = window;
+ createEnv(html, (err, window) => {
+ const { userale } = window;
- expect(userale.log({})).to.equal(true);
- expect(userale.log()).to.equal(false);
- expect(userale.log(null)).to.equal(false);
+ expect(userale.log({})).to.equal(true);
+ expect(userale.log()).to.equal(false);
+ expect(userale.log(null)).to.equal(false);
- window.close();
- done();
- }
+ window.close();
+ done();
});
});
});