diff --git a/.rgignore b/.rgignore new file mode 100644 index 00000000..bcf85800 --- /dev/null +++ b/.rgignore @@ -0,0 +1,2 @@ +src/assets/data/countries-emoji.json +data/countries*.json diff --git a/__tests__/CountryPicker.test.tsx b/__tests__/CountryPicker.test.tsx index 20023a77..634335bb 100644 --- a/__tests__/CountryPicker.test.tsx +++ b/__tests__/CountryPicker.test.tsx @@ -1,13 +1,47 @@ import React from 'react' +import {setImmediate} from 'timers' + import TestRenderer from 'react-test-renderer'; import CountryPicker from '../src/' -it('CountryPicker can be created', () => { - const picker = TestRenderer.create( - {}} />, - ) - expect(picker).toBeDefined() - expect(picker).toMatchSnapshot() +describe('CountryPicker', () => { + // beforeAll(() => { jest.useFakeTimers() }) + // afterAll(() => { jest.useRealTimers() }) + + it('CountryPicker with default options', async () => { + const picker = TestRenderer.create( + {}} withModal={false} />, + ) + await new Promise((yay) => setTimeout(yay, 1000)) + expect(picker).toBeDefined() + expect(picker).toMatchSnapshot() + }) + + it('CountryPicker with translation', async () => { + const picker = TestRenderer.create( + {}} withModal={false} />, + ) + await new Promise((yay) => setTimeout(yay, 1000)) + expect(picker).toBeDefined() + expect(picker).toMatchSnapshot() + }) + }) + +// it('CountryPicker with translation', async () => { +// const picker = TestRenderer.create( +// {}}/>, +// ) +// expect(picker).toBeDefined() +// expect(picker).toMatchSnapshot() + // }) + +// it('CountryPicker without modal', () => { +// const picker = TestRenderer.create( +// {}} withModal={false} />, +// ) +// expect(picker).toBeDefined() +// expect(picker).toMatchSnapshot() +// }) diff --git a/__tests__/__snapshots__/CountryPicker.test.tsx.snap b/__tests__/__snapshots__/CountryPicker.test.tsx.snap index 6ad42324..4122f1da 100644 --- a/__tests__/__snapshots__/CountryPicker.test.tsx.snap +++ b/__tests__/__snapshots__/CountryPicker.test.tsx.snap @@ -1,110 +1,40211 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`CountryPicker can be created 1`] = ` -Array [ +exports[`CountryPicker CountryPicker with default options 1`] = ` + + + + + + + + + + + + + + + 🇦🇫 + + + + + + Afghanistan + + + + + + + + + + + + + 🇦🇽 + + + + + + Åland Islands + + + + + + + + + + + + + 🇦🇱 + + + + + + Albania + + + + + + + + + + + + + 🇩🇿 + + + + + + Algeria + + + + + + + + + + + + + 🇦🇸 + + + + + + American Samoa + + + + + + + + + + + + + 🇦🇩 + + + + + + Andorra + + + + + + + + + + + + + 🇦🇴 + + + + + + Angola + + + + + + + + + + + + + 🇦🇮 + + + + + + Anguilla + + + + + + + + + + + + + 🇦🇶 + + + + + + Antarctica + + + + + + + + + + + + + 🇦🇬 + + + + + + Antigua and Barbuda + + + + + + + + + + + + + 🇦🇷 + + + + + + Argentina + + + + + + + + + + + + + 🇦🇲 + + + + + + Armenia + + + + + + + + + + + + + 🇦🇼 + + + + + + Aruba + + + + + + + + + + + + + 🇦🇺 + + + + + + Australia + + + + + + + + + + + +`; + +exports[`CountryPicker CountryPicker with translation 1`] = ` + + + + + + + + + + + + + + + + + + 🇦🇫 + + + + + + Afganistán + + + + + + + + + + + + + 🇦🇽 + + + + + + Alandia + + + + + + + + + + + + + 🇦🇱 + + + + + + Albania + + + + + + + + + + + + + 🇩🇪 + + + + + + Alemania + + + + + + + + + + + + + 🇦🇩 + + + + + + Andorra + + + + + + + + + + + + 🇦🇴 + + + + + + Angola + + + + + + + - + + + + + 🇦🇮 + + + + + + Anguilla + + + + + - - - , - - - - + + + + 🇦🇶 + + + + + + Antártida + + + + + + + + + + > + + + + 🇦🇬 + + + + + + Antigua y Barbuda + + + + + + + + + + + 🇸🇦 + + + + + + Arabia Saudí + + + + + + + + + + + + + 🇩🇿 + + + + + + Argelia + + + + + + + + + + + + + 🇦🇷 + + + + + + Argentina + + + + + + + + + + + + + 🇦🇲 + + + + + + Armenia + + + + + + + + + + + + + 🇦🇼 + + + + + + Aruba + + + + + + + - - - - - - - , -] + + + `; diff --git a/package.json b/package.json index 5fc0b20a..0745d170 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "react-native-country-picker-modal", "version": "2.0.0", "description": "react-native country picker", - "main": "lib/index.js", + "main": "node_modules/expo/AppEntry.js", "types": "lib/index.d.ts", "repository": { "type": "git", @@ -11,14 +11,15 @@ "scripts": { "start": "yarn config:dev && expo start", "start:web": "yarn config:dev && expo start -w --dev", - "tsc": "node_modules/.bin/tsc --noEmit", - "build": "rm -rf lib/ && node_modules/.bin/tsc && cp -rf ./src/assets ./lib && yarn minify", + "tscdry": "node_modules/.bin/tsc --noEmit", + "build": "rm -rf lib/ && tsc && cp -rf ./src/assets ./lib && yarn minify", "minify": "yarn minify:emoji", "minify:emoji": "./scripts/minify.js ./lib/assets/data/countries-emoji.json", "config:dev": "json -I -f package.json -e 'this.main=\"node_modules/expo/AppEntry.js\"'", "config:npm": "json -I -f package.json -e 'this.main=\"lib/index.js\"'", "lint": "tslint --project .", "test": "TZ=Europe/Paris jest", + "data": "yarn data:image && yarn data:emoji && yarn data:cca2 && yarn data:regions && yarn data:subregions", "data:image": "rm -rf ./data/countries.json && ./scripts/transform-world-countries.js > ./data/countries.json", "data:emoji": "rm -rf ./data/countries-emoji.json && ./scripts/transform-world-countries.js --emoji > ./data/countries-emoji.json", "data:cca2": "rm -rf ./data/cca2.json && ./scripts/transform-world-countries.js --cca2 > ./data/cca2.json", @@ -53,7 +54,7 @@ }, "devDependencies": { "@babel/core": "^7.19.1", - "@types/jest": "^29.0.3", + "@types/jest": "^26.0.24", "@types/node-emoji": "^1.8.2", "@types/prop-types": "^15.7.5", "@types/react": "^17.0.39", @@ -68,6 +69,7 @@ "husky": "^3.0.0", "jest": "^29.0.3", "jest-environment-jsdom": "^29.0.3", + "jest-environment-node": "^29.0.3", "jest-expo": "^46.0.1", "json": "^11.0.0", "prettier": "^2.7.1", @@ -75,7 +77,7 @@ "react-dom": "^18.0.0", "react-native": "^0.69.5", "react-native-web": "^0.18.9", - "react-test-renderer": "^18.0.0", + "react-test-renderer": "^18.2.0", "tslint": "^6.1.3", "tslint-config-prettier": "^1.18.0", "typescript": "^4.8.3", @@ -83,7 +85,7 @@ }, "jest": { "preset": "react-native", - "testEnvironment": "jsdom", + "testEnvironment": "node", "moduleFileExtensions": [ "js", "jsx", @@ -104,7 +106,7 @@ }, "husky": { "hooks": { - "pre-commit": "yarn lint && yarn tsc" + "pre-commit": "yarn lint && yarn tscdry" } }, "resolutions": { diff --git a/yarn.lock b/yarn.lock index 4af3b841..11b7b211 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2572,13 +2572,13 @@ dependencies: "@types/istanbul-lib-report" "*" -"@types/jest@^29.0.3": - version "29.0.3" - resolved "https://registry.yarnpkg.com/@types/jest/-/jest-29.0.3.tgz#b61a5ed100850686b8d3c5e28e3a1926b2001b59" - integrity sha512-F6ukyCTwbfsEX5F2YmVYmM5TcTHy1q9P5rWlRbrk56KyMh3v9xRGUO3aa8+SkvMi0SHXtASJv1283enXimC0Og== +"@types/jest@^26.0.24": + version "26.0.24" + resolved "https://registry.yarnpkg.com/@types/jest/-/jest-26.0.24.tgz#943d11976b16739185913a1936e0de0c4a7d595a" + integrity sha512-E/X5Vib8BWqZNRlDxj9vYXhsDwPYbPINqKF9BsnSoon4RQ0D9moEuLD8txgyypFLH7J4+Lho9Nr/c8H0Fi+17w== dependencies: - expect "^29.0.0" - pretty-format "^29.0.0" + jest-diff "^26.0.0" + pretty-format "^26.0.0" "@types/jsdom@^20.0.0": version "20.0.0" @@ -4324,6 +4324,11 @@ detect-newline@^3.0.0: resolved "https://registry.yarnpkg.com/detect-newline/-/detect-newline-3.1.0.tgz#576f5dfc63ae1a192ff192d8ad3af6308991b651" integrity sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA== +diff-sequences@^26.6.2: + version "26.6.2" + resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-26.6.2.tgz#48ba99157de1923412eed41db6b6d4aa9ca7c0b1" + integrity sha512-Mv/TDa3nZ9sbc5soK+OoA74BsS3mL37yixCvUAQkiuA4Wz6YtwP/K47n2rv2ovzHZvoiQeA5FTQOschKkEwB0Q== + diff-sequences@^29.0.0: version "29.0.0" resolved "https://registry.yarnpkg.com/diff-sequences/-/diff-sequences-29.0.0.tgz#bae49972ef3933556bcb0800b72e8579d19d9e4f" @@ -4559,7 +4564,7 @@ expand-range@^1.8.1: dependencies: fill-range "^2.1.0" -expect@^29.0.0, expect@^29.0.3: +expect@^29.0.3: version "29.0.3" resolved "https://registry.yarnpkg.com/expect/-/expect-29.0.3.tgz#6be65ddb945202f143c4e07c083f4f39f3bd326f" integrity sha512-t8l5DTws3212VbmPL+tBFXhjRHLmctHB0oQbL8eUc6S7NzZtYUhycrFO9mkxA0ZUC6FAWdNi7JchJSkODtcu1Q== @@ -5953,6 +5958,16 @@ jest-config@^29.0.3: slash "^3.0.0" strip-json-comments "^3.1.1" +jest-diff@^26.0.0: + version "26.6.2" + resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-26.6.2.tgz#1aa7468b52c3a68d7d5c5fdcdfcd5e49bd164394" + integrity sha512-6m+9Z3Gv9wN0WFVasqjCL/06+EFCMTqDEUl/b87HYK2rAPTyfz4ZIuSlPhY51PIQRWx5TaxeF1qmXKe9gfN3sA== + dependencies: + chalk "^4.0.0" + diff-sequences "^26.6.2" + jest-get-type "^26.3.0" + pretty-format "^26.6.2" + jest-diff@^29.0.3: version "29.0.3" resolved "https://registry.yarnpkg.com/jest-diff/-/jest-diff-29.0.3.tgz#41cc02409ad1458ae1bf7684129a3da2856341ac" @@ -8005,7 +8020,7 @@ pretty-bytes@5.6.0: resolved "https://registry.yarnpkg.com/pretty-bytes/-/pretty-bytes-5.6.0.tgz#356256f643804773c82f64723fe78c92c62beaeb" integrity sha512-FFw039TmrBqFK8ma/7OL3sDz/VytdtJr044/QUJtH0wK9lb9jLq9tJyIxUwtQJHwar2BqtiA4iCWSwo9JLkzFg== -pretty-format@^26.5.2, pretty-format@^26.6.2: +pretty-format@^26.0.0, pretty-format@^26.5.2, pretty-format@^26.6.2: version "26.6.2" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-26.6.2.tgz#e35c2705f14cb7fe2fe94fa078345b444120fc93" integrity sha512-7AeGuCYNGmycyQbCqd/3PWH4eOoX/OiCa0uphp57NVTeAGdJGaAliecxwBDHYQCIvrW7aDBZCYeNTP/WX69mkg== @@ -8024,7 +8039,7 @@ pretty-format@^27.5.1: ansi-styles "^5.0.0" react-is "^17.0.1" -pretty-format@^29.0.0, pretty-format@^29.0.3: +pretty-format@^29.0.3: version "29.0.3" resolved "https://registry.yarnpkg.com/pretty-format/-/pretty-format-29.0.3.tgz#23d5f8cabc9cbf209a77d49409d093d61166a811" integrity sha512-cHudsvQr1K5vNVLbvYF/nv3Qy/F/BcEKxGuIeMiVMRHxPOO1RxXooP8g/ZrwAp7Dx+KdMZoOc7NxLHhMrP2f9Q== @@ -8280,7 +8295,7 @@ react-shallow-renderer@16.15.0, react-shallow-renderer@^16.13.1, react-shallow-r object-assign "^4.1.1" react-is "^16.12.0 || ^17.0.0 || ^18.0.0" -react-test-renderer@^18.0.0: +react-test-renderer@^18.2.0: version "18.2.0" resolved "https://registry.yarnpkg.com/react-test-renderer/-/react-test-renderer-18.2.0.tgz#1dd912bd908ff26da5b9fca4fd1c489b9523d37e" integrity sha512-JWD+aQ0lh2gvh4NM3bBM42Kx+XybOxCpgYK7F8ugAlpaTSnWsX+39Z4XkOykGZAHrjwwTZT3x3KxswVWxHPUqA==