kentcdodds / babel-plugin-macros

šŸŽ£ Allows you to build simple compile-time libraries
https://npm.im/babel-plugin-macros
MIT License
2.62k stars 135 forks source link

A fixture is broken and some snapshots need updating/fixing #132

Closed futagoza closed 4 years ago

futagoza commented 4 years ago

I'm getting the following errors after running npm run setup -s (sorry, tried wrapping it in collapsable markdown but that just made it unreadable):

NOTE: Just to be clear, I've checked the commit log, and the last commit related to source code didn't seem to break anything (it was back in June), but it seems to be broken after that (upstream dependency changes perhaps?); and then to make thing more confusing, the Travis logs for commits after June 2019 show less errors then my local Windows 10 machine.

$ npm run setup -s
husky > Setting up git hooks
husky > Done
added 1248 packages from 638 contributors and audited 901224 packages in 495.231s
found 2 moderate severity vulnerabilities
  run `npm audit fix` to fix them, or `npm audit` for details
[build] Successfully compiled 1 file with Babel.
[build] npm run build --silent exited with code 0
[lint] npm run lint --silent exited with code 0
[test]  PASS  src/__tests__/create-macros.js (7.777s)
[test]  FAIL  src/__tests__/index.js (14.018s)
[test]   ā— Console
[test] 
[test]     console.error src/index.js:295
[test]       There was an error trying to load the config "configurableMacro" for the macro imported from "./configurable.macro. Please see the error thrown for more information.
[test]     console.error src/index.js:274
[test]       The macro plugin options' configurableMacro property was not an object or null.
[test]
[test]   ā— macros ā€ŗ works with require destructuring
[test]
[test]     TypeError: C:\projects\babel-plugin-macros\src\__tests__\index.js: ./fixtures/emotion.macro: Property value of TemplateElement expected to have the following:
[test]     Property raw expected type of string but got undefined
[test]
[test]       23 |       const quasi = styledRef.parentPath.parentPath.get('quasi')
[test]       24 |       const val = quasi.evaluate().value.trim()
[test]     > 25 |       const replacement = t.templateLiteral([t.templateElement(val)], [])
[test]          |                                                ^
[test]       26 |       quasi.replaceWith(replacement)
[test]       27 |     }
[test]       28 |   })
[test]
[test]       at Object.validate (node_modules/@babel/types/lib/definitions/utils.js:190:13)
[test]       at validateField (node_modules/@babel/types/lib/validators/validate.js:22:9)
[test]       at validate (node_modules/@babel/types/lib/validators/validate.js:16:3)
[test]       at builder (node_modules/@babel/types/lib/builders/builder.js:38:27)
[test]       at Object.templateElement (node_modules/@babel/types/lib/builders/generated/index.js:538:31)
[test]       at forEach (src/__tests__/fixtures/emotion.macro.js:25:48)
[test]           at Array.forEach (<anonymous>)
[test]       at macro (src/__tests__/fixtures/emotion.macro.js:21:21)
[test]       at macro (src/index.js:61:12)
[test]       at applyMacros (src/index.js:225:14)
[test]
[test]   ā— macros ā€ŗ works with require destructuring and aliasing
[test]
[test]     TypeError: C:\projects\babel-plugin-macros\src\__tests__\index.js: ./fixtures/emotion.macro: Property value of TemplateElement expected to have the following:
[test]     Property raw expected type of string but got undefined
[test]
[test]       23 |       const quasi = styledRef.parentPath.parentPath.get('quasi')
[test]       24 |       const val = quasi.evaluate().value.trim()
[test]     > 25 |       const replacement = t.templateLiteral([t.templateElement(val)], [])
[test]          |                                                ^
[test]       26 |       quasi.replaceWith(replacement)
[test]       27 |     }
[test]       28 |   })
[test]
[test]       at Object.validate (node_modules/@babel/types/lib/definitions/utils.js:190:13)
[test]       at validateField (node_modules/@babel/types/lib/validators/validate.js:22:9)
[test]       at validate (node_modules/@babel/types/lib/validators/validate.js:16:3)
[test]       at builder (node_modules/@babel/types/lib/builders/builder.js:38:27)
[test]       at Object.templateElement (node_modules/@babel/types/lib/builders/generated/index.js:538:31)
[test]       at forEach (src/__tests__/fixtures/emotion.macro.js:25:48)
[test]           at Array.forEach (<anonymous>)
[test]       at macro (src/__tests__/fixtures/emotion.macro.js:21:21)
[test]       at macro (src/index.js:61:12)
[test]       at applyMacros (src/index.js:225:14)
[test]
[test]   ā— macros ā€ŗ Supports named imports
[test]
[test]     TypeError: C:\projects\babel-plugin-macros\src\__tests__\index.js: ./fixtures/emotion.macro: Property value of TemplateElement expected to have the following:
[test]     Property raw expected type of string but got undefined
[test]
[test]       23 |       const quasi = styledRef.parentPath.parentPath.get('quasi')
[test]       24 |       const val = quasi.evaluate().value.trim()
[test]     > 25 |       const replacement = t.templateLiteral([t.templateElement(val)], [])
[test]          |                                                ^
[test]       26 |       quasi.replaceWith(replacement)
[test]       27 |     }
[test]       28 |   })
[test]
[test]       at Object.validate (node_modules/@babel/types/lib/definitions/utils.js:190:13)
[test]       at validateField (node_modules/@babel/types/lib/validators/validate.js:22:9)
[test]       at validate (node_modules/@babel/types/lib/validators/validate.js:16:3)
[test]       at builder (node_modules/@babel/types/lib/builders/builder.js:38:27)
[test]       at Object.templateElement (node_modules/@babel/types/lib/builders/generated/index.js:538:31)
[test]       at forEach (src/__tests__/fixtures/emotion.macro.js:25:48)
[test]           at Array.forEach (<anonymous>)
[test]       at macro (src/__tests__/fixtures/emotion.macro.js:21:21)
[test]       at macro (src/index.js:61:12)
[test]       at applyMacros (src/index.js:225:14)
[test]
[test]   ā— macros ā€ŗ optionally keep imports in combination with babel-preset-env (#80)
[test]
[test]     expect(received).toMatchSnapshot(hint)
[test]
[test]     Snapshot name: `macros optionally keep imports in combination with babel-preset-env (#80): optionally keep imports in combination with babel-preset-env (#80) 1`
[test]
[test]     - Snapshot
[test]     + Received
[test]
[test]       import macro from './fixtures/keep-imports.macro'
[test]       const red = macro('noop')
[test]
[test]             ā†“ ā†“ ā†“ ā†“ ā†“ ā†“
[test]
[test]     - import macro from './fixtures/keep-imports.macro';
[test]     - const red = macro('noop');
[test]     + "use strict";
[test]     +
[test]     + var _keepImports = require("./fixtures/keep-imports.macro");
[test]     +
[test]     + var _keepImports2 = _interopRequireDefault(_keepImports);
[test]     +
[test]     + function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
[test]     +
[test]     + const red = (0, _keepImports2.default)('noop');
[test]
[test]       at tester (node_modules/babel-plugin-tester/dist/index.js:206:44)
[test]       at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:158:13)
[test]       at asyncGeneratorStep (node_modules/babel-plugin-tester/dist/index.js:23:103)
[test]       at _next (node_modules/babel-plugin-tester/dist/index.js:25:194)
[test]
[test]   ā— macros ā€ŗ throws an error if the macro is not properly wrapped
[test]
[test]     expect(received).toMatchSnapshot(hint)
[test]
[test]     Snapshot name: `macros throws an error if the macro is not properly wrapped: throws an error if the macro is not properly wrapped 1`
[test]
[test]     - Snapshot
[test]     + Received
[test]
[test]       import unwrapped from './fixtures/non-wrapped.macro'
[test]       unwrapped('hey')
[test]
[test]             ā†“ ā†“ ā†“ ā†“ ā†“ ā†“
[test]
[test]     - Error: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/author.md#writing-a-macro
[test]     + Error: The macro imported from "./fixtures/non-wrapped.macro" must be wrapped in "createMacro" which you can get from "babel-plugin-macros". Please refer to the documentation to see how to do this properly: https://github.com/kentcdodds/babel-plugin-macros/blob/master/other/docs/author.md#writing-a-macro      
[test]
[test]       at tester (node_modules/babel-plugin-tester/dist/index.js:206:44)
[test]       at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:158:13)
[test]       at asyncGeneratorStep (node_modules/babel-plugin-tester/dist/index.js:23:103)
[test]       at _next (node_modules/babel-plugin-tester/dist/index.js:25:194)
[test]
[test]   ā— macros ā€ŗ prepends the relative path for errors thrown by the macro
[test]
[test]     expect(received).toMatchSnapshot(hint)
[test]
[test]     Snapshot name: `macros prepends the relative path for errors thrown by the macro: prepends the relative path for errors thrown by the macro 1`
[test]
[test]     - Snapshot
[test]     + Received
[test]
[test]       import errorThrower from './fixtures/error-thrower.macro'
[test]       errorThrower('hey')
[test]
[test]             ā†“ ā†“ ā†“ ā†“ ā†“ ā†“
[test]
[test]     - Error: very unhelpful
[test]     + Error: ./fixtures/error-thrower.macro: very unhelpful
[test]
[test]       at tester (node_modules/babel-plugin-tester/dist/index.js:206:44)
[test]       at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:158:13)
[test]       at asyncGeneratorStep (node_modules/babel-plugin-tester/dist/index.js:23:103)
[test]       at _next (node_modules/babel-plugin-tester/dist/index.js:25:194)
[test]
[test]   ā— macros ā€ŗ appends the npm URL for errors thrown by node modules
[test]
[test]     expect(received).toMatchSnapshot(hint)
[test]
[test]     Snapshot name: `macros appends the npm URL for errors thrown by node modules: appends the npm URL for errors thrown by node modules 1`
[test]
[test]     - Snapshot
[test]     + Received
[test]
[test]       import errorThrower from 'babel-plugin-macros-test-error-thrower.macro'
[test]       errorThrower('hi')
[test]
[test]             ā†“ ā†“ ā†“ ā†“ ā†“ ā†“
[test]
[test]     - Error: not helpful Learn more: https://www.npmjs.com/package/babel-plugin-macros-test-error-thrower.macro
[test]     + Error: babel-plugin-macros-test-error-thrower.macro: not helpful Learn more: https://www.npmjs.com/package/babel-plugin-macros-test-error-thrower.macro
[test]
[test]       at tester (node_modules/babel-plugin-tester/dist/index.js:206:44)
[test]       at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:158:13)
[test]       at asyncGeneratorStep (node_modules/babel-plugin-tester/dist/index.js:23:103)
[test]       at _next (node_modules/babel-plugin-tester/dist/index.js:25:194)
[test]
[test]   ā— macros ā€ŗ appends the npm URL for errors thrown by node modules with a slash
[test]
[test]     expect(received).toMatchSnapshot(hint)
[test]
[test]     Snapshot name: `macros appends the npm URL for errors thrown by node modules with a slash: appends the npm URL for errors thrown by node modules with a slash 1`
[test]
[test]     - Snapshot
[test]     + Received
[test]
[test]       import errorThrower from 'babel-plugin-macros-test-error-thrower/macro'
[test]       errorThrower('hi')
[test]
[test]             ā†“ ā†“ ā†“ ā†“ ā†“ ā†“
[test]
[test]     - Error: not helpful Learn more: https://www.npmjs.com/package/babel-plugin-macros-test-error-thrower
[test]     + Error: babel-plugin-macros-test-error-thrower/macro: not helpful Learn more: https://www.npmjs.com/package/babel-plugin-macros-test-error-thrower    
[test]
[test]       at tester (node_modules/babel-plugin-tester/dist/index.js:206:44)
[test]       at Object.<anonymous> (node_modules/babel-plugin-tester/dist/index.js:158:13)
[test]       at asyncGeneratorStep (node_modules/babel-plugin-tester/dist/index.js:23:103)
[test]       at _next (node_modules/babel-plugin-tester/dist/index.js:25:194)
[test]
[test]  ā€ŗ 5 snapshots failed.
[test]  ā€ŗ 3 snapshots obsolete.
[test]    ā€¢ macros Supports named imports: Supports named imports 1
[test]    ā€¢ macros works with require destructuring and aliasing: works with require destructuring and aliasing 1
[test]    ā€¢ macros works with require destructuring: works with require destructuring 1
[test] ----------|----------|----------|----------|----------|-------------------|
[test] File      |  % Stmts | % Branch |  % Funcs |  % Lines | Uncovered Line #s |
[test] ----------|----------|----------|----------|----------|-------------------|
[test] All files |      100 |      100 |      100 |      100 |                   |
[test]  index.js |      100 |      100 |      100 |      100 |                   |
[test] ----------|----------|----------|----------|----------|-------------------|
[test] Snapshot Summary
[test]  ā€ŗ 5 snapshots failed from 1 test suite. Inspect your code changes or re-run jest with `-u` to update them.
[test]  ā€ŗ 3 snapshots obsolete from 1 test suite. To remove them all, re-run jest with `-u`.
[test]    ā†³ src/__tests__/index.js
[test]        ā€¢ macros Supports named imports: Supports named imports 1
[test]        ā€¢ macros works with require destructuring and aliasing: works with require destructuring and aliasing 1
[test]        ā€¢ macros works with require destructuring: works with require destructuring 1
[test]
[test] Test Suites: 1 failed, 1 passed, 2 total
[test] Tests:       8 failed, 23 passed, 31 total
[test] Snapshots:   5 failed, 3 obsolete, 23 passed, 28 total
[test] Time:        19.359s
[test] Ran all test suites.
[test] npm run test --silent -- --coverage exited with code 1
kentcdodds commented 4 years ago

I've just pushed a fix to this. Everything should be good now! Thank you!