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

TypeError: sourceMap.map.originalPositionFor is not a function #5589

Closed
jy95 opened this issue Feb 16, 2018 · 9 comments
Closed

TypeError: sourceMap.map.originalPositionFor is not a function #5589

jy95 opened this issue Feb 16, 2018 · 9 comments

Comments

@jy95
Copy link

jy95 commented Feb 16, 2018

Do you want to request a feature or report a bug?
Bug about Manual Mocks with Filehound

What is the current behavior?

 FAIL  __tests__\methods\createFromJSON.ts
  ● Test suite failed to run

    TypeError: sourceMap.map.originalPositionFor is not a function

      1 | 'use strict';
    > 2 | const filehound = jest.genMockFromModule('filehound');
      3 | 
      4 | // temp files
      5 | let result;
      
      at mapSourcePosition (node_modules/source-map-support/source-map-support.js:213:42)
      at wrapCallSite (node_modules/source-map-support/source-map-support.js:357:20)
      at node_modules/source-map-support/source-map-support.js:392:26
          at Array.map (<anonymous>)
      at Function.prepareStackTrace (node_modules/source-map-support/source-map-support.js:391:24)
      at Object.setBounds (node_modules/bluebird/js/release/debuggability.js:677:42)
      at Object.<anonymous>.module.exports (node_modules/bluebird/js/release/promise.js:772:11)
      at Object.<anonymous> (node_modules/bluebird/js/release/bluebird.js:9:36)
      at Object.<anonymous> (node_modules/filehound/lib/filehound.js:13:17)
      at Object.<anonymous> (node_modules/filehound/index.js:1:107)
      at Object.<anonymous> (__mocks__/filehound.js:2:24)
      at Object.<anonymous> (lib/MediaScan.js:44:17)
      at Object.<anonymous> (__tests__/__helpers__/_constants.ts:6:21)
      at Object.<anonymous> (__tests__/methods/createFromJSON.ts:59:20)

If the current behavior is a bug, please provide the steps to reproduce and
either a repl.it demo through https://repl.it/languages/jest or a minimal
repository on GitHub that we can yarn install and yarn test.

No so much, just create a filehound.js inside a __mocks__ folder

// __mocks__/filehound.js

'use strict';
const filehound = jest.genMockFromModule('filehound');

// temp files
let result;

function find() {
    if (result !== undefined){
        return Promise.resolve(result);
    }
    // if nothing provided , throw error
    return Promise.reject(new Error("VAUDOU"));
}

function __setResult(ExpectedResult) {
    result = ExpectedResult;
}

filehound.__setResult = __setResult;
filehound.find = find;

module.exports = filehound;

What is the expected behavior?
It should work.

Please provide your exact Jest configuration and mention your Jest, node,
yarn/npm version and operating system.

Jest version : 22.3.0
Node version : 8.9.3
NPM version : 5.6.0
OS : Windows 10 Version 1709

My jest.config.js :

// jest.config.js
module.exports = {
    verbose: true,
    "moduleFileExtensions": [
        "ts",
        "tsx",
        "js"
    ],
    "transform": {
        "^.+\\.(ts|tsx)$": "<rootDir>/__tests__/__helpers__/preprocessor.js"
    },
    "testMatch": [
        "<rootDir>/__tests__/**/*.(ts|tsx|js)"
    ],
    "testPathIgnorePatterns": ["<rootDir>/node_modules/", "<rootDir>/__tests__/__helpers__/"],
    "automock": true, // just because I'm lazy to always add the 2 lines of mock modules ^^
    "unmockedModulePathPatterns": ['bluebird']
    // "collectCoverage": true
};

Edit : Without unmockedModulePathPatterns, I got TypeError: Cannot set property 'noConflict' of undefined like Issue 90

@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

This was actually fixed as part of #5177

@SimenB SimenB closed this as completed Feb 17, 2018
@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

Wait no, I can't reproduce with jest 22.3.0. Can you create a repo showing the failure?

@jy95
Copy link
Author

jy95 commented Feb 17, 2018

Ok, here is the repository : https://github.com/jy95/mediaScan .
For now, I use a ugly workaround for this case (basically , a short copy/paste of the compiled lib) : mock filehound.
Just to be clear, I first compile the src and then run the tests.

Edit : I just need to find out why the addNewPath method isn't working in Jest when It works in its ES6 version with AVA.

@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

I cannot reproduce your error.

I get this:
image

Can you create a branch in your repo I can checkout, run jest, and see the failure?

@jy95
Copy link
Author

jy95 commented Feb 17, 2018

If you check the code of Filehound, you can see the methods create,paths,ext returns this (the current instance) and then the findmethod returns something so using the default jest.mock that returns by default undefined will not be useful ^^

@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

Can you create a branch with the necessary change so I can reproduce?

@jy95
Copy link
Author

jy95 commented Feb 17, 2018

The only change is to replace the content of __mocks__/filehound.js with the one of my initial message.
Like jest show, it will crash before anything else is done :

 FAIL  __tests__\methods\createFromJSON.ts
   Test suite failed to run

    TypeError: sourceMap.map.originalPositionFor is not a function

      1 | 'use strict';
    > 2 | const filehound = jest.genMockFromModule('filehound');
      3 | 
      4 | // temp files
      5 | let result;

Edit : from what I see on your screen, it doesn't seem jest.genMockFromModule(moduleName) is doing its job very well

@SimenB
Copy link
Member

SimenB commented Feb 17, 2018

I have placed the text from OP in __mocks__/filehound.js and I cannot reproduce (beyond the errors I got in the screenshot I posted).

Please push a branch I can pull down. Will close until then

@SimenB SimenB closed this as completed Feb 17, 2018
@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants