From f7ee9c1539632901c456e640555863a3ecd0a9c0 Mon Sep 17 00:00:00 2001 From: Jakob Reschke Date: Tue, 24 May 2016 20:48:11 +0200 Subject: [PATCH 1/4] do relative imports correctly --- MiniBase.js | 2 +- tests/LayerInliningTests.js | 3 ++- tests/LayerTests.js | 2 +- tests/TracingTests.js | 2 +- 4 files changed, 5 insertions(+), 4 deletions(-) diff --git a/MiniBase.js b/MiniBase.js index 5048002..6b70e3a 100644 --- a/MiniBase.js +++ b/MiniBase.js @@ -24,7 +24,7 @@ */ 'use strict'; -import { $A } from 'miniprototype.js'; +import { $A } from './miniprototype.js'; // Non-Lively Compatibility export var Global = {}; diff --git a/tests/LayerInliningTests.js b/tests/LayerInliningTests.js index 2db78cf..9a9528a 100644 --- a/tests/LayerInliningTests.js +++ b/tests/LayerInliningTests.js @@ -1,6 +1,7 @@ 'use strict'; -import { default as cop } from 'copv2/Layers.js'; +import { default as cop } from '../copv2/Layers.js'; +import '../MiniBase.js' cop.tests = {}; cop.tests.LayerInliningTests = {}; diff --git a/tests/LayerTests.js b/tests/LayerTests.js index 59a1e5d..09603ec 100644 --- a/tests/LayerTests.js +++ b/tests/LayerTests.js @@ -23,7 +23,7 @@ */ 'use strict'; -import { default as cop, Layer, LayerableObject, Global } from 'copv2/Layers.js'; +import { default as cop, Layer, LayerableObject, Global } from '../copv2/Layers.js'; // COP Example from: Hirschfeld, Costanza, Nierstrasz. 2008. // Context-oriented Programming. JOT) diff --git a/tests/TracingTests.js b/tests/TracingTests.js index 8bdddf8..177736c 100644 --- a/tests/TracingTests.js +++ b/tests/TracingTests.js @@ -1,4 +1,4 @@ -import { default as cop } from 'copv2/Layers'; +import { default as cop } from '../copv2/Layers'; function TestCase() {}; // TODO: get rid of this TestCase.subclass('cop.tests.TracingTests.TracerTest', From f52ea0e8f0bbb074c822c12a76ac8249fa8e1184 Mon Sep 17 00:00:00 2001 From: Jakob Reschke Date: Tue, 24 May 2016 20:51:46 +0200 Subject: [PATCH 2/4] make unit tests runnable in Node.js add new test script in package.json include global .babelrc (was only in karma.conf.js so far) arrange that chai is in the globals when mocha runs the tests because importing/requiring it in the browser would be another challenge (karma provides the global chai because it is listed in the frameworks) --- .babelrc | 3 +++ package.json | 4 +++- tests/globalChai.js | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .babelrc create mode 100644 tests/globalChai.js diff --git a/.babelrc b/.babelrc new file mode 100644 index 0000000..c13c5f6 --- /dev/null +++ b/.babelrc @@ -0,0 +1,3 @@ +{ + "presets": ["es2015"] +} diff --git a/package.json b/package.json index 7a7342e..fa314bc 100644 --- a/package.json +++ b/package.json @@ -7,7 +7,9 @@ "test": "tests" }, "scripts": { - "test": "karma start --single-run", + "test": "npm run test-node && npm run test-karma", + "test-karma": "karma start --single-run", + "test-node": "mocha --compilers js:babel-core/register tests", "test-chrome-only": "karma start --single-run --browsers Chrome", "test-continuously": "karma start", "test-continuously-chrome-only": "karma start --browsers Chrome", diff --git a/tests/globalChai.js b/tests/globalChai.js new file mode 100644 index 0000000..03e17ad --- /dev/null +++ b/tests/globalChai.js @@ -0,0 +1,3 @@ +// only to be run with node (or rather mocha), not in a browser + +global.chai = require('chai'); From 67bac98eb757bae6d704af796d2739f3157dd380 Mon Sep 17 00:00:00 2001 From: Jakob Reschke Date: Tue, 24 May 2016 20:56:05 +0200 Subject: [PATCH 3/4] do not use console.group when it is not available node.js console does not have it, it is a non-standard browser feature --- tests/LayerTests.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/LayerTests.js b/tests/LayerTests.js index 09603ec..147ec95 100644 --- a/tests/LayerTests.js +++ b/tests/LayerTests.js @@ -827,9 +827,11 @@ describe('cop', function () { .refineObject(o, { say: function(a) {return cop.proceed(a + " World") + "!"}}) assert.equal(o.say("Hello"), "Say: Hello", "test is broken"); cop.withLayers([l], function() { - console.group("SayHello"); + if (typeof console.group !== 'undefined') + console.group("SayHello"); var result = o.say("Hello") - console.groupEnd("SayHello"); + if (typeof console.group !== 'undefined') + console.groupEnd("SayHello"); assert.equal(result, "Say: Hello World!", "adapting arguments is broken"); }.bind(this)); }); From 96d409b417b83e37956adeb02c0d12bfe18969e8 Mon Sep 17 00:00:00 2001 From: Jakob Reschke Date: Tue, 24 May 2016 21:17:44 +0200 Subject: [PATCH 4/4] require globalChai.js explicitly --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index fa314bc..e48dfbd 100644 --- a/package.json +++ b/package.json @@ -9,7 +9,7 @@ "scripts": { "test": "npm run test-node && npm run test-karma", "test-karma": "karma start --single-run", - "test-node": "mocha --compilers js:babel-core/register tests", + "test-node": "mocha tests --compilers js:babel-core/register --require tests/globalChai.js", "test-chrome-only": "karma start --single-run --browsers Chrome", "test-continuously": "karma start", "test-continuously-chrome-only": "karma start --browsers Chrome",