yandex / reselector

Use React Components in css selectors
https://npm.im/reselector
Other
45 stars 10 forks source link

wdio e2e tests, TID generation logic #86

Open vitalyiegorov opened 4 years ago

vitalyiegorov commented 4 years ago

Hi @lttb, thanks for this great library, we are perfectly using it in our unit tests but I need your help with the following issue:

We have a monorepo project with webdriverio e2e tests, and we cannot use this selectors in our e2e tests because they generate different hashes for the components, how we can improve to generate same hashes independently of cwd, because for example react-app is started from /project/web/ and e2e is started from /e2e/web/

I have tried changing parentPath from utils.js with env variable:

const projectPath = process.env.RESELECTOR_PATH === undefined ? process.cwd().toLowerCase() : path.resolve(process.env.RESELECTOR_PATH);

But this does not solves the issue, please guide me though the logic so I could make a PR.

lttb commented 4 years ago

Hi @vitalyiegorov,

Excuse me for the delay, please.

Could you try to redefine a getId option in reselector.config in case of your project, please?

You can find the implementation example here: https://github.com/lttb/reselector/blob/29e4c7c509b45fe9eb4d124b67de7757fbf4c168/src/utils.js#L135-L136

For example,

reslector.config.js

const stringHash = require('string-hash')

module.exports = {
  // options
  getId(filename, name) {
    return stringHash(/* your case of getting the monorepo identifier for file and component name */).toString(16)
  }
}

I'm not sure why your example with projectPath doesn't work, but I think an experiment with getId might be a good starting point