From b3f91f794cc9622855146ebdcf1cf9a2f363fd34 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Tue, 3 Jul 2018 14:25:59 +0200 Subject: [PATCH 1/4] Fix error triggered when props are undefined. In some weird corner cases, the following error is thrown: `TypeError: Cannot read property 'className' of undefined`. --- .eslintcache | 1 + src/utils.js | 1 + 2 files changed, 2 insertions(+) create mode 100644 .eslintcache diff --git a/.eslintcache b/.eslintcache new file mode 100644 index 0000000..8d17e25 --- /dev/null +++ b/.eslintcache @@ -0,0 +1 @@ +{"/Users/yamafaktory/dev/jest-glamor-react/index.js":{"size":179,"mtime":1530620384082,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/jest.config.js":{"size":189,"mtime":1530620384083,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/jest.config.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/other/setup-test-framework.js":{"size":167,"mtime":1530620384086,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/other/setup-test-framework.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/dom-nodes.js":{"size":2205,"mtime":1530620384088,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/dom-nodes.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/example.js":{"size":1185,"mtime":1530620384089,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/example.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/matchers.js":{"size":3818,"mtime":1530620384089,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/matchers.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/replace-selectors.js":{"size":3699,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/replace-selectors.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/serializer.js":{"size":3093,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/serializer.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/snapshot-diff.js":{"size":1391,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/snapshot-diff.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/utils.js":{"size":2574,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/utils.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/matchers.js":{"size":1823,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/matchers.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/replace-selectors.js":{"size":538,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/replace-selectors.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/serializer.js":{"size":2752,"mtime":1530620384092,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/serializer.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/utils.js":{"size":5092,"mtime":1530620633856,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/utils.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}} \ No newline at end of file diff --git a/src/utils.js b/src/utils.js index e540dfd..bb86f82 100644 --- a/src/utils.js +++ b/src/utils.js @@ -35,6 +35,7 @@ function getSelectors(nodes) { // eslint-disable-next-line function getSelectorsFromProps(selectors, node) { const props = typeof node.props === 'function' ? node.props() : node.props + if (!props) return [] const className = props.className || props.class if (className) { selectors = selectors.concat( From 0cc26399f4e8b58318643a79189c467e8c24b864 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Tue, 3 Jul 2018 14:29:00 +0200 Subject: [PATCH 2/4] =?UTF-8?q?Add=20.eslintcache=20in=20.gitignore=20?= =?UTF-8?q?=F0=9F=8E=89.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 7c6bb31..09048d2 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ dist .opt-in .opt-out .DS_Store +.eslintcache # these cause more harm than good # when working with contributors From 21d00ea7312368212fccbd0f35be9d1e12d82295 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Tue, 3 Jul 2018 14:31:46 +0200 Subject: [PATCH 3/4] =?UTF-8?q?Drop=20that=20file=20=E2=99=BB=EF=B8=8F.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintcache | 1 - 1 file changed, 1 deletion(-) delete mode 100644 .eslintcache diff --git a/.eslintcache b/.eslintcache deleted file mode 100644 index 8d17e25..0000000 --- a/.eslintcache +++ /dev/null @@ -1 +0,0 @@ -{"/Users/yamafaktory/dev/jest-glamor-react/index.js":{"size":179,"mtime":1530620384082,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/index.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/jest.config.js":{"size":189,"mtime":1530620384083,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/jest.config.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/other/setup-test-framework.js":{"size":167,"mtime":1530620384086,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/other/setup-test-framework.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/dom-nodes.js":{"size":2205,"mtime":1530620384088,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/dom-nodes.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/example.js":{"size":1185,"mtime":1530620384089,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/example.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/matchers.js":{"size":3818,"mtime":1530620384089,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/matchers.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/replace-selectors.js":{"size":3699,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/replace-selectors.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/serializer.js":{"size":3093,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/serializer.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/snapshot-diff.js":{"size":1391,"mtime":1530620384090,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/snapshot-diff.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/utils.js":{"size":2574,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/__tests__/utils.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/matchers.js":{"size":1823,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/matchers.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/replace-selectors.js":{"size":538,"mtime":1530620384091,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/replace-selectors.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/serializer.js":{"size":2752,"mtime":1530620384092,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/serializer.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}},"/Users/yamafaktory/dev/jest-glamor-react/src/utils.js":{"size":5092,"mtime":1530620633856,"hashOfConfig":"d1xt3m","results":{"filePath":"/Users/yamafaktory/dev/jest-glamor-react/src/utils.js","messages":[],"errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0}}} \ No newline at end of file From 03b429ba2dbb4d10281740be4a6b67015f2687d9 Mon Sep 17 00:00:00 2001 From: Davy Duperron Date: Tue, 3 Jul 2018 22:25:01 +0200 Subject: [PATCH 4/4] Add small test case. --- src/__tests__/utils.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/__tests__/utils.js b/src/__tests__/utils.js index 16ef714..9edc27c 100644 --- a/src/__tests__/utils.js +++ b/src/__tests__/utils.js @@ -78,4 +78,11 @@ describe('getSelectors', () => { ) expect(getSelectors(wrapper)).toHaveLength(1) }) + it('works when a node has no props (edge case)', () => { + const wrapper = renderer.create(
).toJSON() + const nodes = getNodes(wrapper) + // Simulate a node with no props. + delete nodes[0].props + expect(getSelectors(nodes)).toHaveLength(0) + }) })