Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move to ESM #83

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Open

Conversation

tommy-mitchell
Copy link

@tommy-mitchell tommy-mitchell commented Aug 21, 2023

Per #82.

  • Converts project from CJS to ESM
  • Bumps minimum Node.js version to 18 and updates CI matrix
    • Uses "engines" version range from AVA
  • Uses Object.hasOwn() instead of Object.prototype.hasOwnProperty.call()
  • Updates code style to use xo (based on configs from AVA)
  • Updates dependencies
    • The well-known-symbols shim update changes how well-known symbols are formatted (Symbol.iterator -> Symbol(Symbol.iterator))
  • Removes lodash

A few tests are failing, seems to have to do with serialization and object pointers.

@tommy-mitchell tommy-mitchell mentioned this pull request Aug 21, 2023
6 tasks
@tommy-mitchell
Copy link
Author

Perhaps we could use smoldash instead of lodash for _.cloneDeep and _.merge: https://github.com/marvinhagemeister/smoldash/blob/51b5872d8c0887e25e0ccd54555b35f0d7ecb2a8/src/index.ts#L286-L339

Related, what is _.isLength doing? Is it needed?

@novemberborn
Copy link
Member

  • Updates dependencies (except for well-known-symbols)

That library has transferred actually (not sure if it's been republished yet). There's definitely more well-known symbols out there but maybe there's a better way to encode them.

Perhaps we could use smoldash instead of lodash for _.cloneDeep and _.merge: marvinhagemeister/smoldash@51b5872/src/index.ts#L286-L339

I'm not bothered either way. There may also be some APIs we could use, e.g. the structured clone implementation in the node:v8 module.

Related, what is _.isLength doing? Is it needed?

Looks like it's a heuristic for identifying when to treat an object as a list (array). But it could be inlined:

https://github.com/lodash/lodash/blob/ddfd9b11a0126db2302cb70ec9973b66baec0975/lodash.js#L11713-L11716

I'd go with 18. 16 is end of life in 9 days.

@tommy-mitchell
Copy link
Author

tommy-mitchell commented Jul 21, 2024

Updated to bump minimum Node.js version and remove Lodash in favor of inlining _.isLength and using spread and structuredClone over _.merge and _.cloneDeep. Also updates well-known-symbols to v4, which changes how well-known symbols are formatted:

- Symbol.iterator
+ Symbol(Symbol.iterator)

Still need to fix the failing tests. One issue seems to be how undefined is handled between spread and _.merge, as mentioned in #78

Failing Tests

serialization-fixtures › pointer serialization equals the same tree
test/serialization-fixtures.js:11

10:   t.log(diff(deserialize(serialization), describe(tree)));               
11:   t.true(compareDescriptors(deserialize(serialization), describe(tree)));
12: });                                                                      

Value is not `true`:

false

› file://test/serialization-fixtures.js:11:8



max-depth › properties with increased indentation respect the maxDepth when formatted

test/max-depth.js:45

44: test('properties with increased indentation respect the maxDepth when fo…
45:   t.snapshot(format({                                                    
46:     foo: {                                                               

Did not match snapshot

Difference (- actual, + expected):

`{␊
-   fooundefined…undefined␊
+   foo: …,␊
}`

› file://test/max-depth.js:45:4



diff › diff pointers hidden behind maxDepth

test/diff.js:594

593:                                                                         
594:   t.notThrows(() => {                                                   
595:     // `maxDepth: 1` means that `a.b` is not normally deserialized, and…

Function threw:

Error {
message: 'Formatter buffer never received a formatted value.',
}

› SingleValueFormatter.finalize (file://lib/formatUtils.js:119:10)
› format (file://lib/diff.js:181:38)
› Object.diffDescriptors (file://lib/diff.js:343:6)
› file://test/diff.js:598:15
› file://test/diff.js:594:4



format › escapes ' according to theme

test/format.js:93

92:     };                                                          
93:     t.snapshot(_format(escapeQuote, {theme: testTheme}));       
94:     t.snapshot(_format(escapeQuote + '\n', {theme: testTheme}));

Did not match snapshot

Difference (- actual, + expected):

- '<undefined\\\'undefined>'
+ '<\\\'>'

› exec (file://test/format.js:93:5)



format › escapes " according to theme

test/format.js:93

92:     };                                                          
93:     t.snapshot(_format(escapeQuote, {theme: testTheme}));       
94:     t.snapshot(_format(escapeQuote + '\n', {theme: testTheme}));

Did not match snapshot

Difference (- actual, + expected):

- '<undefined\\"undefined>'
+ '<\\">'

› exec (file://test/format.js:93:5)



format › escapes ` according to theme

test/format.js:93

92:     };                                                          
93:     t.snapshot(_format(escapeQuote, {theme: testTheme}));       
94:     t.snapshot(_format(escapeQuote + '\n', {theme: testTheme}));

Did not match snapshot

Difference (- actual, + expected):

- '<undefined\\`undefined>'
+ '<\\`>'

› exec (file://test/format.js:93:5)



format › format pointers hidden behind maxDepth

test/format.js:476

475:                                                                         
476:   t.notThrows(() => {                                                   
477:     // `maxDepth: 1` means that `a.b` is not normally deserialized, and…

Function threw:

Error {
message: 'Formatter buffer never received a formatted value.',
}

› SingleValueFormatter.finalize (file://lib/formatUtils.js:119:10)
› Object.formatDescriptor (file://lib/format.js:92:39)
› file://test/format.js:480:15
› file://test/format.js:476:4



serialize-and-encode › deserialized object with pointer to itself is equivalent to the original

test/serialize-and-encode.js:42

41:                                                  
42:     t.true(                                      
43:       compareDescriptors(deserialized, original),

the deserialized descriptor equals the original

Value is not `true`:

false

› exec (file://test/serialize-and-encode.js:42:9)



serialize-and-encode › deserialized plugin is equivalent to the original

test/serialize-and-encode.js:42

41:                                                  
42:     t.true(                                      
43:       compareDescriptors(deserialized, original),

the deserialized descriptor equals the original

Value is not `true`:

false

› exec (file://test/serialize-and-encode.js:42:9)

@tommy-mitchell
Copy link
Author

tommy-mitchell commented Jul 21, 2024

Updated to use the defaults package to handle merging theme configs.

Failing Tests

serialization-fixtures › pointer serialization equals the same tree
test/serialization-fixtures.js:11

10:   t.log(diff(deserialize(serialization), describe(tree)));               
11:   t.true(compareDescriptors(deserialize(serialization), describe(tree)));
12: });                                                                      

Value is not `true`:

false

› file://test/serialization-fixtures.js:11:8



diff › diff pointers hidden behind maxDepth

test/diff.js:594

593:                                                                         
594:   t.notThrows(() => {                                                   
595:     // `maxDepth: 1` means that `a.b` is not normally deserialized, and…

Function threw:

Error {
message: 'Formatter buffer never received a formatted value.',
}

› SingleValueFormatter.finalize (file://lib/formatUtils.js:119:10)
› format (file://lib/diff.js:181:38)
› Object.diffDescriptors (file://lib/diff.js:343:6)
› file://test/diff.js:598:15
› file://test/diff.js:594:4



format › format pointers hidden behind maxDepth

test/format.js:477

476:                                                                         
477:   t.notThrows(() => {                                                   
478:     // `maxDepth: 1` means that `a.b` is not normally deserialized, and…

Function threw:

Error {
message: 'Formatter buffer never received a formatted value.',
}

› SingleValueFormatter.finalize (file://lib/formatUtils.js:119:10)
› Object.formatDescriptor (file://lib/format.js:92:39)
› file://test/format.js:481:15
› file://test/format.js:477:4



serialize-and-encode › deserialized object with pointer to itself is equivalent to the original

test/serialize-and-encode.js:42

41:                                                  
42:     t.true(                                      
43:       compareDescriptors(deserialized, original),

the deserialized descriptor equals the original

Value is not `true`:

false

› exec (file://test/serialize-and-encode.js:42:9)



serialize-and-encode › deserialized plugin is equivalent to the original

test/serialize-and-encode.js:42

41:                                                  
42:     t.true(                                      
43:       compareDescriptors(deserialized, original),

the deserialized descriptor equals the original

Value is not `true`:

false

› exec (file://test/serialize-and-encode.js:42:9)

─

5 tests failed

@tommy-mitchell
Copy link
Author

Maybe the well-known-symbols update should be done in a separate PR? Since it would be a breaking change (as mentioned in #59). It could be nice to release a refactor update, and then follow with a breaking change update.

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