cljsrn

https://github.com/drapanjanas/re-natal | https://github.com/drapanjanas/re-natal/wiki/FAQ | https://github.com/condense/mercury-app/wiki | https://github.com/seantempesta/expo-cljs-template/ https://www.npmjs.com/package/create-expo-cljs-app
zendevil 2021-01-10T12:33:28.272800Z

What’s the best way to do tests in react native when using shadow-cljs?

zendevil 2021-01-17T06:56:06.002Z

how did you use jest with clojurescript?

zendevil 2021-01-17T07:03:44.002200Z

can you give an example file?

2021-01-17T14:00:32.012300Z

I have an example project, there is some setup necessary. https://github.com/mynomoto/reagent-expo/tree/jest-test

zendevil 2021-01-17T14:28:51.014700Z

how do you run the tests?

2021-01-17T14:29:26.015Z

It is on the readme.

zendevil 2021-01-17T14:30:45.016Z

shadow-cljs watch test?

2021-01-17T14:32:15.016200Z

That will build the test files. You need to run yarn jest on another terminal to run jest.

zendevil 2021-01-17T14:32:49.016400Z

i don’t use yarn

zendevil 2021-01-17T14:32:52.016600Z

i use npm

2021-01-17T14:33:26.016800Z

npm run jest

zendevil 2021-01-17T14:36:10.017500Z

how does it know which files contain the tests?

zendevil 2021-01-17T14:36:40.017700Z

how does jest know which directory to look at?

zendevil 2021-01-17T14:45:18.018500Z

so in my own project i have to add this in my package.json?

zendevil 2021-01-17T14:46:20.018800Z

the testMatch keyword?

zendevil 2021-01-17T14:46:32.019Z

Sorry for the ignorance, I haven’t used jest

2021-01-17T14:47:17.019200Z

There are many ways to do it. That project is a working example, if you follow it you should get things working.

2021-01-17T14:48:12.019400Z

You can see the commits I did to add jest. Those will show you the necessary changes.

zendevil 2021-01-17T14:48:36.019600Z

where are you based?

zendevil 2021-01-17T14:53:24.019800Z

what is the snapshotResolver?

zendevil 2021-01-17T14:55:16.020Z

I’m getting the following error when running shadow-cljs watch test

zendevil 2021-01-17T14:55:18.020200Z

-- Spec failed --------------------  {:target :npm-module, :output-dir “test-out”, :build-id :test} should contain key: :entries | key   | spec      | |==========+=================| | :entries | (coll-of    | |     | simple-symbol? | |     | :distinct   | |     | true      | |     | :min-count   | |     | 1       | |     | :kind     | |     | vector?)    | -- Relevant specs ------- :shadow.build.targets.npm-module/target:  (clojure.spec.alpha/keys   :req-un   [:shadow.build.targets.shared/output-dir   :shadow.build.targets.npm-module/entries]   :opt-un   [:shadow.build.targets.npm-module/runtime   :shadow.build.targets.shared/devtools]) :shadow.build.config/build+target:  (clojure.spec.alpha/and   :shadow.build.config/build   (clojure.spec.alpha/multi-spec   shadow.build.config/target-spec   :target)) ------------------------- Detected 1 error

2021-01-17T14:56:23.020400Z

I live in Brazil. That are for view snapshots. Google for jest snapshots to see the use case for those.

2021-01-17T14:58:41.020600Z

That is probably a shadow breaking change. Not sure about what goes in that key and I'm afk right now.

2021-01-17T15:01:53.020800Z

Actually an empty vector on :entries should work.

zendevil 2021-01-17T18:15:40.022Z

I’m getting the following error after adding the []

zendevil 2021-01-17T18:15:42.022200Z

Invalid configuration -- Spec failed --------------------  {:target ...,   :output-dir ...,   :entries [],       ^^   :build-id ...} should satisfy  (<= 1 (count %) Integer/MAX_VALUE) -- Relevant specs ------- :shadow.build.targets.npm-module/entries:  (clojure.spec.alpha/coll-of   clojure.core/simple-symbol?   :distinct   true   :min-count   1   :kind   clojure.core/vector?) :shadow.build.targets.npm-module/target:  (clojure.spec.alpha/keys   :req-un   [:shadow.build.targets.shared/output-dir   :shadow.build.targets.npm-module/entries]   :opt-un   [:shadow.build.targets.npm-module/runtime   :shadow.build.targets.shared/devtools]) :shadow.build.config/build+target:  (clojure.spec.alpha/and   :shadow.build.config/build   (clojure.spec.alpha/multi-spec   shadow.build.config/target-spec   :target)) ------------------------- Detected 1 error

zendevil 2021-01-17T20:14:16.026100Z

I have the following in my package.json

zendevil 2021-01-17T20:14:17.026300Z

“jest”: { “preset”: “react-native”, “testPathIgnorePatterns”: [ “/node_modules/“, “/.shadow-cljs/” ], “testMatch”: [ “/test-out//*_test.js” ], “snapshotResolver”: “<rootDir>/customSnapshotResolver.js” }

zendevil 2021-01-17T20:14:34.026500Z

but when I run npm run jest, I get the following error:

zendevil 2021-01-17T20:14:57.026700Z

npm ERR! missing script: jest npm ERR!  npm ERR! Did you mean this? npm ERR!   test npm ERR! A complete log of this run can be found in: npm ERR!   /Users/prikshetsharma/.npm/logs/2021-01-17T2013_25_770Z-debug.log prikshetsharma@vpn13-222 Humboi % npm run jest npm ERR! missing script: jest npm ERR!  npm ERR! Did you mean this? npm ERR!   test npm ERR! A complete log of this run can be found in: npm ERR!   /Users/prikshetsharma/.npm/logs/2021-01-17T2014_42_077Z-debug.log

2021-01-18T13:02:52.032Z

Oh, on npm it is npm run test

zendevil 2021-01-18T14:23:51.032200Z

that gives the following error:

zendevil 2021-01-18T14:23:56.032400Z

> Humboi@0.0.1 test /Users/prikshetsharma/Desktop/Humboi > jest sh: jest: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! Humboi@0.0.1 test: jest npm ERR! spawn ENOENT npm ERR!  npm ERR! Failed at the Humboi@0.0.1 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR!   /Users/prikshetsharma/.npm/logs/2021-01-18T1422_50_869Z-debug.log

zendevil 2021-01-18T14:24:09.032600Z

and the log file has the following content:

zendevil 2021-01-18T14:24:10.032800Z

0 info it worked if it ends with ok 1 verbose cli [ ‘/usr/local/bin/node’, ‘/usr/local/bin/npm’, ‘run’, ‘test’ ] 2 info using npm@6.14.8 3 info using node@v14.15.1 4 verbose run-script [ ‘pretest’, ‘test’, ‘posttest’ ] 5 info lifecycle Humboi@0.0.1~pretest: Humboi@0.0.1 6 info lifecycle Humboi@0.0.1~test: Humboi@0.0.1 7 verbose lifecycle Humboi@0.0.1~test: unsafe-perm in lifecycle true 8 verbose lifecycle Humboi@0.0.1test: PATH: /usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/node-gyp-bin:/Users/prikshetsharma/Desktop/Humboi/node_modules/.bin:/opt/X11/bin:/Users/prikshetsharma/.rbenv/shims:/usr/local/opt/ruby/bin:/usr/local/opt/ruby/lib/ruby/gems/2.7.0/bin:/usr/local/opt/ruby/bin:/usr/local/bin:/Users/prikshetsharma/Library/Android/sdk/platform-tools:/Users/prikshetsharma/Library/Android/sdk/emulator:/usr/local/opt/ruby/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Library/TeX/texbin:/usr/local/share/dotnet:/opt/X11/bin:/.dotnet/tools:/Library/Apple/usr/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Users/prikshetsharma/.rvm/bin:/usr/local/bin:/Users/prikshetsharma/Library/Android/sdk/emulator:/Users/prikshetsharma/Library/Android/sdk/tools:/Users/prikshetsharma/Library/Android/sdk/tools/bin:/Users/prikshetsharma/Library/Android/sdk/platform-tools 9 verbose lifecycle Humboi@0.0.1~test: CWD: /Users/prikshetsharma/Desktop/Humboi 10 silly lifecycle Humboi@0.0.1~test: Args: [ ‘-c’, ‘jest’ ] 11 info lifecycle Humboi@0.0.1~test: Failed to exec test script 12 verbose stack Error: Humboi@0.0.1 test: jest 12 verbose stack spawn ENOENT 12 verbose stack at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/node_modules/npm-lifecycle/lib/spawn.js:48:18) 12 verbose stack at ChildProcess.emit (events.js:315:20) 12 verbose stack at maybeClose (internal/child_process.js:1048:16) 12 verbose stack at Process.ChildProcess.handle.onexit (internal/childprocess.js:288:5) 13 verbose pkgid Humboi@0.0.1 14 verbose cwd /Users/prikshetsharma/Desktop/Humboi 15 verbose Darwin 20.2.0 16 verbose argv “/usr/local/bin/node” “/usr/local/bin/npm” “run” “test” 17 verbose node v14.15.1 18 verbose npm v6.14.8 19 error code ELIFECYCLE 20 error syscall spawn 21 error file sh 22 error errno ENOENT 23 error Humboi@0.0.1 test: jest 23 error spawn ENOENT 24 error Failed at the Humboi@0.0.1 test script. 24 error This is probably not a problem with npm. There is likely additional logging output above. 25 verbose exit [ 1, true ]

2021-01-18T14:39:58.033Z

Did you add the dependencies on package.json? And run npm install after adding the dependencies?

zendevil 2021-01-18T14:43:12.033200Z

yes I have already run npm install

zendevil 2021-01-18T14:44:24.033400Z

but am still getting the error

zendevil 2021-01-18T14:44:27.033600Z

how to fix it?

2021-01-18T14:49:00.033800Z

Is the project on github? Or can you paste your package.json?

zendevil 2021-01-18T14:51:55.034Z

2021-01-18T15:04:29.034400Z

I think this is the lock one. I want the one used for configuration.

zendevil 2021-01-18T15:09:00.034600Z

{ "name": "Humboi", "version": "0.0.1", "private": true, "scripts": { "android": "react-native run-android", "ios": "react-native run-ios", "start": "react-native start", "test": "jest", "lint": "eslint ." }, "dependencies": { "@react-native-async-storage/async-storage": "^1.13.2", "@react-native-community/cameraroll": "^4.0.1", "@react-native-community/masked-view": "^0.1.10", "@react-navigation/bottom-tabs": "^5.11.3", "@react-navigation/native": "^5.9.0", "@unimodules/core": "^7.0.0", "create-react-class": "^15.7.0", "expo-camera": "^9.1.1", "react": "16.13.1", "react-dom": "^16.13.0", "react-native": "0.63.4", "react-native-camera": "^3.42.0", "react-native-camera-roll-picker": "^2.0.0", "react-native-elements": "^3.1.0", "react-native-gesture-handler": "^1.9.0", "react-native-google-signin": "^2.1.1", "react-native-reanimated": "^1.13.2", "react-native-safe-area-context": "^3.1.9", "react-native-screens": "^2.16.1", "react-native-vector-icons": "^7.1.0", "react-native-video": "^4.3.0" }, "devDependencies": { "@babel/core": "^7.8.4", "@babel/runtime": "^7.8.4", "@react-native-community/eslint-config": "^1.1.0", "@testing-library/react-native": "^7.1.0", "babel-jest": "^25.1.0", "eslint": "^6.5.1", "jest": "^25.1.0", "metro-react-native-babel-preset": "^0.59.0", "react-test-renderer": "16.13.1" }, "jest": { "preset": "react-native", "testPathIgnorePatterns": [ "/node_modules/", "/.shadow-cljs/" ], "testMatch": [ "/test-out//*_test.js" ], "snapshotResolver": "<rootDir>/customSnapshotResolver.js" } }

2021-01-18T15:12:39.034800Z

What is the output of running npm install?

zendevil 2021-01-18T15:15:02.035Z

npm WARN @react-native-community/cameraroll@4.0.1 requires a peer of react-native@>=0.57 <=0.62 but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-barcode-scanner-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-camera-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-face-detector-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-file-system-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-permissions-interface@* but none is installed. You must install peer dependencies yourself. removed 9 packages and audited 1380 packages in 4.168s 14 packages are looking for funding  run npm fund for details found 4 low severity vulnerabilities  run npm audit fix to fix them, or npm audit for details prikshetsharma@vpn13-222 Humboi % npm run test > Humboi@0.0.1 test /Users/prikshetsharma/Desktop/Humboi > jest sh: jest: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! Humboi@0.0.1 test: jest npm ERR! spawn ENOENT npm ERR!  npm ERR! Failed at the Humboi@0.0.1 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR!   /Users/prikshetsharma/.npm/logs/2021-01-18T1442_54_628Z-debug.log prikshetsharma@vpn13-222 Humboi % npm install npm WARN @react-native-community/cameraroll@4.0.1 requires a peer of react-native@>=0.57 <=0.62 but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-barcode-scanner-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-camera-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-face-detector-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-file-system-interface@* but none is installed. You must install peer dependencies yourself. npm WARN expo-camera@9.1.1 requires a peer of unimodules-permissions-interface@* but none is installed. You must install peer dependencies yourself. removed 9 packages and audited 1380 packages in 5.365s 14 packages are looking for funding  run npm fund for details found 4 low severity vulnerabilities  run npm audit fix to fix them, or npm audit for details

2021-01-18T15:28:13.035200Z

Try to run npm run test. You did not installed jest globally so running jest is not expected to work.

zendevil 2021-01-19T01:35:50.043900Z

But npm run test gives the following:

zendevil 2021-01-19T01:35:52.044100Z

> Humboi@0.0.1 test /Users/prikshetsharma/Desktop/Humboi > jest sh: jest: command not found npm ERR! code ELIFECYCLE npm ERR! syscall spawn npm ERR! file sh npm ERR! errno ENOENT npm ERR! Humboi@0.0.1 test: jest npm ERR! spawn ENOENT npm ERR!  npm ERR! Failed at the Humboi@0.0.1 test script. npm ERR! This is probably not a problem with npm. There is likely additional logging output above. npm ERR! A complete log of this run can be found in: npm ERR!   /Users/prikshetsharma/.npm/logs/2021-01-19T0135_32_701Z-debug.log’]

2021-01-19T01:45:46.044500Z

You should remove the test entry on package.json scripts.

zendevil 2021-01-20T04:57:52.055200Z

after removing and running npm run test, I get the following:

zendevil 2021-01-20T04:57:52.055400Z

> Humboi@0.0.1 test /Users/prikshetsharma/Desktop/Humboi > echo ‘Error: no test specified’ Error: no test specified

2021-01-20T14:50:23.056300Z

Do you have tests on the project?

zendevil 2021-01-20T15:43:00.056500Z

nope

2021-01-20T16:01:17.057100Z

Then that is expected. It is telling you that you have no tests.

zendevil 2021-01-20T16:13:11.057300Z

you said remove the test from package.json

zendevil 2021-01-20T16:13:19.057500Z

and npm run jest doesn’t work either

zendevil 2021-01-20T16:13:59.057700Z

Here’s my package.json currently with test script removed:

zendevil 2021-01-20T16:14:00.057900Z

{ “name”: “Humboi”, “version”: “0.0.1", “private”: true, “scripts”: { “android”: “react-native run-android”, “ios”: “react-native run-ios”, “start”: “react-native start”, “lint”: “eslint .” }, “dependencies”: { “@react-native-async-storage/async-storage”: “^1.13.2”, “@react-native-community/cameraroll”: “^4.0.1”, “@react-native-community/masked-view”: “^0.1.10”, “@react-navigation/bottom-tabs”: “^5.11.3”, “@react-navigation/native”: “^5.9.0”, “@unimodules/core”: “^7.0.0”, “@unimodules/react-native-adapter”: “^6.0.0”, “create-react-class”: “^15.7.0”, “expo-camera”: “^9.1.1”, “expo-media-library”: “^10.0.0”, “react”: “16.13.1”, “react-dom”: “^16.13.0”, “react-native”: “0.63.4”, “react-native-beautiful-video-recorder”: “^2.0.1”, “react-native-camera”: “^3.42.0”, “react-native-camera-roll-picker”: “^2.0.0”, “react-native-elements”: “^3.1.0”, “react-native-gesture-handler”: “^1.9.0”, “react-native-google-signin”: “^2.1.1”, “react-native-reanimated”: “^1.13.2”, “react-native-safe-area-context”: “^3.1.9”, “react-native-screens”: “^2.16.1”, “react-native-unimodules”: “^0.12.0”, “react-native-vector-icons”: “^7.1.0”, “react-native-video”: “^4.3.0”, “unimodules-permissions-interface”: “^5.4.0” }, “devDependencies”: { “@babel/core”: “^7.8.4", “@babel/runtime”: “^7.8.4", “@react-native-community/eslint-config”: “^1.1.0", “@testing-library/react-native”: “^7.1.0", “babel-jest”: “^25.1.0", “eslint”: “^6.5.1", “jest”: “^25.5.4", “metro-react-native-babel-preset”: “^0.59.0", “react-test-renderer”: “16.13.1" }, “jest”: { “preset”: “react-native”, “testPathIgnorePatterns”: [ “/node_modules/“, “/.shadow-cljs/” ], “testMatch”: [ “/test-out//*_test.js” ], “snapshotResolver”: “<rootDir>/customSnapshotResolver.js” } }

2021-01-20T17:21:26.058200Z

Now the command is working but it could not find any tests. You need some tests on the project.

zendevil 2021-01-20T18:13:30.058400Z

I have the tests in the test/myapp/core_test.cljs directory

2021-01-20T18:34:50.058600Z

Did you compile the tests to javascript with shadow-cljs watch test?

zendevil 2021-01-21T04:57:51.000100Z

yes

2021-01-21T13:32:26.002300Z

And you can find the compiled test on the test-out folder?

zendevil 2021-01-22T00:49:55.002500Z

yes

zendevil 2021-01-22T00:50:15.002700Z

but there are no test scripts for npm run test.

zendevil 2021-01-22T00:50:23.002900Z

what test script should I add?

2021-01-22T01:05:47.003100Z

Jest works without a test script. The message you are receiving says that it could not find any tests.

2021-01-10T14:58:40.272900Z

I'm not sure what is the best way but I used jest and liked the result.