Skip to content

Commit

Permalink
initial conversion of test/examples to ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
trusktr committed Sep 21, 2021
1 parent ac261d6 commit 179e506
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 21 deletions.
6 changes: 4 additions & 2 deletions test/examples/check-topics.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

var expectedTopics = [
// '/turtle1/cmd_vel', '/turtle1/color_sensor', '/turtle1/pose',
Expand Down
6 changes: 4 additions & 2 deletions test/examples/fibonacci.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

describe('Fibonacci Example', function() {
it('Fibonacci', function(done) {
Expand Down
15 changes: 10 additions & 5 deletions test/examples/karma.conf.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,22 @@ module.exports = function(config) {
config.set({

// Base path, that will be used to resolve files and exclude
basePath: '',
basePath: '../../',

// Testing frameworks
frameworks: ['mocha', 'chai'],

// List of files / patterns to load in the browser
files: [
"../../node_modules/eventemitter2/lib/eventemitter2.js",
"../../build/roslib.js",
"../require-shim.js",
"*.js"
// Make some file available to be fetched/imported, but not included in the HTML.
{pattern: 'build/roslib.esm.js', serve: true, included: false},
{pattern: 'test/util/shim/chai.js', serve: true, included: false},
{pattern: 'test/util/shim/stream.js', serve: true, included: false},

// This file maps some import specifiers to our module shims.
'test/util/write-importmap.js',

{pattern: 'test/examples/*.example.js', type: 'module'},
],

// test results reporter to use
Expand Down
6 changes: 4 additions & 2 deletions test/examples/params.examples.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

describe('Param setting', function() {
var ros = new ROSLIB.Ros({
Expand Down
6 changes: 4 additions & 2 deletions test/examples/pubsub.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

describe('Topics Example', function() {
this.timeout(1000);
Expand Down
6 changes: 4 additions & 2 deletions test/examples/tf.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

describe('TF2 Republisher Example', function() {
it('tf republisher', function(done) {
Expand Down
6 changes: 4 additions & 2 deletions test/examples/tf_service.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import * as ROSLIB from '../../src/RosLibNode.js';

const {expect} = chai;

describe('TF2 Republisher Service Example', function() {
it('tf republisher', function(done) {
Expand Down
12 changes: 8 additions & 4 deletions test/examples/topic-listener.example.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
var expect = require('chai').expect;
var ROSLIB = require('../..');
import chai from 'chai';
import Stream from 'stream';
import * as ROSLIB from '../../src/RosLibNode.js';

const TransformStream = Stream.Transform;
const {expect} = chai;

var ros = new ROSLIB.Ros({
url: 'ws://localhost:9090'
Expand Down Expand Up @@ -55,8 +59,8 @@ describe('Topics Example', function() {
});
});

// Only in Node.js, not browsers (f.e. during Mocha tests, but not during Karma tests)
if (ROSLIB.Topic.prototype.toStream) {
var TransformStream = require('stream').Transform;
describe('Topic Streams are readable and writable', function() {
this.timeout(1000);

Expand Down Expand Up @@ -90,7 +94,7 @@ if (ROSLIB.Topic.prototype.toStream) {
var stream = createAndStreamTopic('/echo/test-stream').toStream();
var expected = messages.slice();

expect(stream).to.be.instanceof(require('stream'));
expect(stream).to.be.instanceof(Stream);
stream.on('data', function(message) {
expect(message).to.be.eql(expected.shift());
});
Expand Down
3 changes: 3 additions & 0 deletions test/util/shim/stream.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// This is empty because `stream` is not used when in a browser (and this file
// is a shim for when in a browser).
export default {}
1 change: 1 addition & 0 deletions test/util/write-importmap.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ document.write(/*html*/`
{
"imports": {
"chai": "/base/test/util/shim/chai.js",
"stream": "/base/test/util/shim/stream.js",
"xmldom": "/base/src/util/shim/xmldom.js",
"cbor-js": "/base/src/util/shim/cbor.js",
"/base/src/RosLibNode.js": "/base/build/roslib.esm.js"
Expand Down

0 comments on commit 179e506

Please sign in to comment.