Skip to content

Commit 35273cf

Browse files
authored
Migrate cjs to esm: utility, core, general, platform and browser tests (#1207)
1 parent c3b4b73 commit 35273cf

22 files changed

Lines changed: 70 additions & 58 deletions

test/api.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var API = require('../src/api');
7-
var utility = require('../src/utility');
6+
import API from '../src/api.js';
7+
import utility from '../src/utility.js';
88
utility.setupJSON();
99

1010
function TestTransportGenerator() {
@@ -143,7 +143,7 @@ describe('postSpans', function () {
143143
});
144144

145145
it('should call post on the transport object', async function () {
146-
const urllib = require('../src/browser/url');
146+
const urllib = await import('../src/browser/url.js');
147147
const response = 'yes';
148148
const url = {
149149
parse: function (e) {

test/apiUtility.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var u = require('../src/apiUtility');
7-
var utility = require('../src/utility');
6+
import u from '../src/apiUtility.js';
7+
import utility from '../src/utility.js';
88
utility.setupJSON();
99

1010
describe('buildPayload', function () {

test/browser.core.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
/* globals sinon */
55

66
// Use minimal browser package, with no optional components added.
7-
var Rollbar = require('../src/browser/core');
7+
import Rollbar from '../src/browser/core.js';
88

99
describe('options.captureUncaught', function () {
1010
beforeEach(function (done) {

test/browser.domUtility.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var d = require('../src/browser/domUtility');
6+
import * as d from '../src/browser/domUtility.js';
77

88
function fullElement() {
99
return {

test/browser.predicates.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var p = require('../src/browser/predicates');
6+
import * as p from '../src/browser/predicates.js';
77

88
describe('checkIgnore', function () {
99
it('should return false if is ajax and ignoring ajax errors is on', function () {

test/browser.rollbar.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var Rollbar = require('../src/browser/rollbar');
6+
import Rollbar from '../src/browser/rollbar.js';
77

88
const DUMMY_TRACE_ID = 'some-trace-id';
99
const DUMMY_SPAN_ID = 'some-span-id';

test/browser.telemetry.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var Instrumenter = require('../src/browser/telemetry');
6+
import Instrumenter from '../src/browser/telemetry.js';
77

88
describe('instrumentNetwork', function () {
99
it('should capture XHR requests with string URL', function (done) {

test/browser.transforms.test.js

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var Rollbar = require('../src/browser/rollbar');
7-
var t = require('../src/browser/transforms');
6+
import Rollbar from '../src/browser/rollbar.js';
7+
import t from '../src/browser/transforms.js';
88

99
function TestClientGen() {
1010
var TestClient = function () {
@@ -527,7 +527,7 @@ describe('addBody', function () {
527527
});
528528

529529
describe('scrubPayload', function () {
530-
it('only scrubs payload data', function (done) {
530+
it('only scrubs payload data', async function () {
531531
var args = [
532532
'a message',
533533
{ scooby: 'doo', okay: 'fizz=buzz&fuzz=baz', user: { id: 42 } },
@@ -547,16 +547,23 @@ describe('scrubPayload', function () {
547547
expect(payload.data.custom.okay).to.eql('fizz=buzz&fuzz=baz');
548548
expect(payload.data.custom.user.id).to.eql(42);
549549

550-
var scrub = require('../src/scrub');
551-
t.addScrubber(scrub)(payload, options, function (e, i) {
552-
expect(i.access_token).to.eql(accessToken);
553-
expect(i.data.custom.scooby).to.not.eql('doo');
554-
expect(payload.data.custom.okay).to.not.eql('fizz=buzz&fuzz=baz');
555-
expect(payload.data.custom.okay).to.match(/fizz=\*+&fuzz=baz/);
556-
expect(payload.data.custom.user.id).to.not.be.ok();
557-
expect(payload.data.custom.user).to.match(/\*+/);
558-
expect(i.data.message).to.eql('a message');
559-
done(e);
550+
const scrubModule = await import('../src/scrub.js');
551+
const scrub = scrubModule.default;
552+
553+
const scrubberFn = t.addScrubber(scrub);
554+
const result = await new Promise((resolve, reject) => {
555+
scrubberFn(payload, options, (err, result) => {
556+
if (err) reject(err);
557+
else resolve(result);
558+
});
560559
});
560+
561+
expect(result.access_token).to.eql(accessToken);
562+
expect(result.data.custom.scooby).to.not.eql('doo');
563+
expect(payload.data.custom.okay).to.not.eql('fizz=buzz&fuzz=baz');
564+
expect(payload.data.custom.okay).to.match(/fizz=\*+&fuzz=baz/);
565+
expect(payload.data.custom.user.id).to.not.be.ok();
566+
expect(payload.data.custom.user).to.match(/\*+/);
567+
expect(result.data.message).to.eql('a message');
561568
});
562569
});

test/browser.transport.test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var truncation = require('../src/truncation');
7-
var Transport = require('../src/browser/transport');
8-
var t = new Transport(truncation);
9-
var utility = require('../src/utility');
6+
import truncation from '../src/truncation.js';
7+
import Transport from '../src/browser/transport.js';
8+
const t = new Transport(truncation);
9+
import * as utility from '../src/utility.js';
1010
utility.setupJSON();
1111

1212
describe('post', function () {

test/browser.url.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* globals it */
44
/* globals sinon */
55

6-
var url = require('../src/browser/url');
6+
import * as url from '../src/browser/url.js';
77

88
describe('parse', function () {
99
it('should return an object full of nulls for a blank url', function () {

0 commit comments

Comments
 (0)