Skip to content

Feature/esm jest - #35

Merged
niemyjski merged 7 commits into
masterfrom
feature/esm-jest
May 7, 2021
Merged

niemyjski merged 7 commits into
masterfrom
feature/esm-jest

Conversation

@niemyjski

@niemyjski niemyjski commented May 5, 2021 •

Copy link
Copy Markdown
Collaborator

Upgraded tests to jest and dropped cjs for esm. Everyone is converting their libraries to esm which supports importing cjs but not the other way around. I was running into issues importing and consuming parse from esm due to a self reference.

@niemyjski
niemyjski requested a review from felixge May 5, 2021 12:37

@niemyjski niemyjski left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixge Can you let me know your thoughts? It would also be nice to upgrade to github actions at some point but I do not have time for that atm.

Comment thread .babelrc
@@ -0,0 +1,5 @@
{
"presets": [
"@babel/preset-env"

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is currently required for jest but I expect soon we can drop babel for tests.

Comment thread __tests__/get-test.js
(function testBasic() {
var trace = get();

//expect(trace[0].getFunction()).toBe(testBasic);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixge I'm not sure why but getFunction always returns undefined/null here

Comment thread __tests__/get-test.js
(function testWrapper() {
(function testBelowFn() {
var trace = get(testBelowFn);
//expect(trace[0].getFunction()).toBe(testWrapper);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@felixge I'm not sure why but getFunction always returns undefined/null here

Comment thread __tests__/parse-test.js
Comment on lines +114 to +115
2: 'Object.asyncJestTest',
4: 'new Promise'

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels weird, but we are parsing what is passed to us. It probably could be better

Comment thread __tests__/parse-test.js
Comment on lines +117 to +130
compare('getTypeName', {
7: null
});
compare('getMethodName', {
2: 'asyncJestTest'
});
compare('getLineNumber', {
0: 88,
1: 92
});
compare('getColumnNumber', {
0: 13
});
compare('isNative');

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These overrides seem brittle depending on node version?

Comment thread index.js
return lines
.map(function(line) {
if (line.match(/^\s*[-]{4,}$/)) {
return self._createParsedCallSite({

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the whole reason I migrated to esm. When this script is used in esm (you can import cjs) this self reference was globalThis and caused runtime issues.

Comment thread __tests__/get-test.js
@@ -0,0 +1,51 @@
import { get } from "../index.js";

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved and renamed these tests, not sure why it thinks it was a delete and new instead of a git mv

@niemyjski

Copy link
Copy Markdown
Collaborator Author

@felixge I'd like your thoughts before merging this unless you are fine with these changes since they are breaking (dropping cjs). I'm currently blocked on my esm project.

@felixge

felixge commented May 7, 2021

Copy link
Copy Markdown
Owner

@niemyjski this LGTM. I don't have time for an in-depth review. My only thought is that perhaps it's time to give this a major (v1) version number to make it clear it's a breaking changing and then keep doing the semver thing going forward.

@niemyjski

Copy link
Copy Markdown
Collaborator Author

Sounds good! I will push this as 1.0.0-pre1 package, I'd like to get a bit more testing on this before cutting a 1.0

@niemyjski
niemyjski merged commit f712874 into master May 7, 2021
@niemyjski
niemyjski deleted the feature/esm-jest branch May 7, 2021 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants