Skip to content

Commit

Permalink
feat(cjs): add cjs option
Browse files Browse the repository at this point in the history
  • Loading branch information
nicojs committed Feb 16, 2021
1 parent b245500 commit 55b1255
Show file tree
Hide file tree
Showing 8 changed files with 126 additions and 63 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules
/reports
/dist
/dist
/cjs
4 changes: 2 additions & 2 deletions .mocharc.jsonc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
{
"spec": "test/node.test.js"
}
"spec": ["test/node.test.?(c)js"]
}
39 changes: 39 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 21 additions & 20 deletions test/browser.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
// A JS file in order to be sure of the line and column numbers
import { getCallId } from '../dist/index.js';

const { expect } = chai;

describe('browser integration', () => {
it('should give the correct location when called from a function', () => {
function act() {
return getCallId();
}
const expected = {
column: 20,
line: 15
};
const actual = act();
expect(actual).deep.contains(expected);
expect(actual.fileName).matches(/^http:\/\/localhost:\d+\/base\/test\/browser.test.js/);
});
});

// A JS file in order to be sure of the line and column numbers
import { getCallId } from '../dist/index.js';

const { expect } = chai;

describe('browser integration', () => {
it('should give the correct location when called from a function', () => {
function act() {
return getCallId();
}
const expected = {
column: 20,
line: 15,
};
const actual = act();
expect(actual).deep.contains(expected);
expect(actual.fileName).matches(
/^http:\/\/localhost:\d+\/base\/test\/browser.test.js/
);
});
});
20 changes: 20 additions & 0 deletions test/node.test.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const { expect } = require('chai');
const { getCallId } = require('..');

// A JS file in order to be sure of the line and column numbers
describe('node cjs', () => {
it('should give the correct location when called from a function', () => {
function act() {
return getCallId();
}
/**
* @type {import('../../dist/call-id').CallId}
*/
const expected = {
fileName: __filename,
column: 12,
line: 18
};
expect(act()).deep.eq(expected);
});
});
40 changes: 20 additions & 20 deletions test/node.test.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
import { expect } from 'chai';
import { getCallId } from '../dist/get-call-id.js';

// A JS file in order to be sure of the line and column numbers
describe('call-id integration', () => {
it('should give the correct location when called from a function', () => {
function act() {
return getCallId();
}
/**
* @type {import('../../dist/call-id').CallId}
*/
const expected = {
fileName: new URL(import.meta.url).pathname,
column: 12,
line: 18
};
expect(act()).deep.eq(expected);
});
});
import { expect } from 'chai';
import { getCallId } from '../dist/index.js';

// A JS file in order to be sure of the line and column numbers
describe('node esm', () => {
it('should give the correct location when called from a function', () => {
function act() {
return getCallId();
}
/**
* @type {import('../../dist/call-id').CallId}
*/
const expected = {
fileName: new URL(import.meta.url).pathname,
column: 12,
line: 18,
};
expect(act()).deep.eq(expected);
});
});
30 changes: 16 additions & 14 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
{
"compilerOptions": {
"target": "ES2015",
"allowJs": true,
"checkJs": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"strict": true,
"sourceMap": true,
"module": "ES2015",
},
"include": ["src"]
}
{
"compilerOptions": {
"target": "ES2015",
"allowJs": true,
"checkJs": true,
"outDir": "dist",
"rootDir": "src",
"declaration": true,
"strict": true,
"sourceMap": true,
"module": "ES2015",
},
"include": [
"src"
]
}
12 changes: 6 additions & 6 deletions tsconfig.lint.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./tsconfig.json",
"include": [
"src",
"test"
]
}
"extends": "./tsconfig.json",
"include": [
"src",
"test"
]
}

0 comments on commit 55b1255

Please sign in to comment.