Skip to content

Commit

Permalink
Add e2e puppeteer test
Browse files Browse the repository at this point in the history
  • Loading branch information
buberdds committed Mar 21, 2022
1 parent 9a15ebd commit d4a784a
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 8 deletions.
23 changes: 23 additions & 0 deletions e2e/popup.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
const { bootstrap } = require('./puppeteer-setup')

describe('test popup', () => {
let extPage, browser

beforeAll(async () => {
const context = await bootstrap({ appUrl: 'http://localhost:1234' })

extPage = context.extPage
browser = context.browser
})

it('should render anchor with label', async () => {
await extPage.bringToFront()
const link = await extPage.$('a')
const label = await link.evaluate(e => e.innerText)
expect(label).toEqual(expect.stringContaining('Open in new tab'))
})

afterAll(async () => {
await browser.close()
})
})
32 changes: 32 additions & 0 deletions e2e/puppeteer-setup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
const puppeteer = require('puppeteer')

async function bootstrap(options = {}) {
const { devtools = false, appUrl } = options
const browser = await puppeteer.launch({
headless: false,
devtools,
args: ['--disable-extensions-except=./build-ext', '--load-extension=./build-ext'],
})

const appPage = await browser.newPage()
await appPage.goto(appUrl, { waitUntil: 'load' })

const targets = await browser.targets()
const extensionTarget = targets.find(({ _targetInfo }) => {
return _targetInfo.title === '__MSG_appName__' && _targetInfo.type === 'background_page'
})
const partialExtensionUrl = extensionTarget._targetInfo.url || ''
const [, , extensionId] = partialExtensionUrl.split('/')
const extPage = await browser.newPage()
const extensionUrl = `chrome-extension://${extensionId}/popup.html`
await extPage.goto(extensionUrl, { waitUntil: 'load' })

return {
appPage,
browser,
extensionUrl,
extPage,
}
}

module.exports = { bootstrap }
2 changes: 1 addition & 1 deletion extension/src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<meta charset="utf-8" />
</head>
<body>
<a href="./popup.html" target="_blank">Open in new tab</a>
<a data-testid="foo" href="./popup.html" target="_blank">Open in new tab</a>

<div id="root" style="min-width: 300px; min-height: 300px"></div>
<script type="module" src="./popup/popup.tsx"></script>
Expand Down
7 changes: 7 additions & 0 deletions internals/jest/jest.ext-e2e-config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module.exports = {
name: 'ext-e2e',
displayName: 'Extension Wallet E2E',
rootDir: './../../e2e',
verbose: true,
testTimeout: 60000,
}
6 changes: 5 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
module.exports = {
projects: ['<rootDir>/internals/jest/jest.web-config.js', '<rootDir>/internals/jest/jest.ext-config.js'],
projects: [
'<rootDir>/internals/jest/jest.web-config.js',
'<rootDir>/internals/jest/jest.ext-config.js',
'<rootDir>/internals/jest/jest.ext-e2e-config.js',
],
}
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"url": "https://github.com/Esya/oasis-wallet.git"
},
"scripts": {
"e2e": "jest --projects internals/jest/jest.ext-e2e-config.js --detectOpenHandles",
"clean": "rm -rf build/ .parcel-cache",
"parcel": "parcel --port 3000 --target web --dist-dir build",
"parcel:build": "parcel build --target web --dist-dir build",
Expand Down Expand Up @@ -100,6 +101,7 @@
"parcel-transformer-env-variables-injection": "0.1.0",
"portable-fetch": "3.0.0",
"prettier": "2.5.1",
"puppeteer": "13.5.1",
"qrcode.react": "1.0.1",
"react": "17.0.2",
"react-app-polyfill": "3.0.0",
Expand Down
Binary file added screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
121 changes: 115 additions & 6 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4980,7 +4980,7 @@ [email protected], bip39@^3.0.4:
pbkdf2 "^3.0.9"
randombytes "^2.0.1"

bl@^4.1.0:
bl@^4.0.3, bl@^4.1.0:
version "4.1.0"
resolved "https://registry.yarnpkg.com/bl/-/bl-4.1.0.tgz#451535264182bec2fbbc83a62ab98cf11d9f7b3a"
integrity sha512-1W07cM9gS6DcLperZfFSj+bWLtaPGSOHWhPiGzXmvVJbRLdG82sH/Kn8EtW1VqWVA54AKf2h5k5BbnIbwF3h6w==
Expand Down Expand Up @@ -5327,7 +5327,7 @@ buffer-xor@^1.0.3:
resolved "https://registry.npmjs.org/buffer-xor/-/buffer-xor-1.0.3.tgz"
integrity sha1-JuYe0UIvtw3ULm42cp7VHYVf6Nk=

buffer@^5.5.0, buffer@^5.6.0:
buffer@^5.2.1, buffer@^5.5.0, buffer@^5.6.0:
version "5.7.1"
resolved "https://registry.yarnpkg.com/buffer/-/buffer-5.7.1.tgz#ba62e7c13133053582197160851a8f648e99eed0"
integrity sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==
Expand Down Expand Up @@ -5638,6 +5638,11 @@ chokidar@^3.4.0, chokidar@^3.5.2:
optionalDependencies:
fsevents "~2.3.2"

chownr@^1.1.1:
version "1.1.4"
resolved "https://registry.yarnpkg.com/chownr/-/chownr-1.1.4.tgz#6fc9d7b42d32a583596337666e7d08084da2cc6b"
integrity sha512-jJ0bqzaylmJtVnNgzTeSOs8DPavpbYgEr/b0YL8/2GO3xJEhInFmhKMUnEJQjZumK7KXGFhUy89PrsJWlakBVg==

chownr@^2.0.0:
version "2.0.0"
resolved "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz"
Expand Down Expand Up @@ -6304,6 +6309,13 @@ [email protected]:
dependencies:
cross-spawn "^7.0.1"

[email protected]:
version "3.1.5"
resolved "https://registry.yarnpkg.com/cross-fetch/-/cross-fetch-3.1.5.tgz#e1389f44d9e7ba767907f7af8454787952ab534f"
integrity sha512-lvb1SBsI0Z7GDwmuid+mU3kWVBwTVUbe7S0H52yaaAdQOXq2YktTCZdlAcNKFzE6QtRz0snpw9bNiPeOIkkQvw==
dependencies:
node-fetch "2.6.7"

cross-spawn@^7.0.0, cross-spawn@^7.0.1, cross-spawn@^7.0.2, cross-spawn@^7.0.3:
version "7.0.3"
resolved "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.3.tgz"
Expand Down Expand Up @@ -6804,6 +6816,11 @@ detective@^5.2.0:
defined "^1.0.0"
minimist "^1.1.1"

[email protected]:
version "0.0.969999"
resolved "https://registry.yarnpkg.com/devtools-protocol/-/devtools-protocol-0.0.969999.tgz#3d6be0a126b3607bb399ae2719b471dda71f3478"
integrity sha512-6GfzuDWU0OFAuOvBokXpXPLxjOJ5DZ157Ue3sGQQM3LgAamb8m0R0ruSfN0DDu+XG5XJgT50i6zZ/0o8RglreQ==

dezalgo@^1.0.0:
version "1.0.3"
resolved "https://registry.npmjs.org/dezalgo/-/dezalgo-1.0.3.tgz"
Expand Down Expand Up @@ -7026,7 +7043,7 @@ encoding@^0.1.11, encoding@^0.1.12:
dependencies:
iconv-lite "^0.6.2"

end-of-stream@^1.0.0, end-of-stream@^1.1.0:
end-of-stream@^1.0.0, end-of-stream@^1.1.0, end-of-stream@^1.4.1:
version "1.4.4"
resolved "https://registry.npmjs.org/end-of-stream/-/end-of-stream-1.4.4.tgz"
integrity sha512-+uw1inIHVPQoaVuHzRyXd21icM+cnt4CzD5rW+NC1wjOUSTOs+Te7FOv7AhN7vS9x/oIyhLP5PR1H+phQAHu5Q==
Expand Down Expand Up @@ -7901,6 +7918,11 @@ fromentries@^1.2.0:
resolved "https://registry.npmjs.org/fromentries/-/fromentries-1.3.2.tgz"
integrity sha512-cHEpEQHUg0f8XdtZCc2ZAhrHzKzT0MrFUTcvx+hfxYu7rGMDc5SKoXFh+n4YigxsHXRzc6OrCshdR1bWH6HHyg==

fs-constants@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/fs-constants/-/fs-constants-1.0.0.tgz#6be0de9be998ce16af8afc24497b9ee9b7ccd9ad"
integrity sha512-y6OAwoSIf7FyjMIv94u+b5rdheZEjzR63GTyZJm5qh4Bi+2YgwLCcI/fPFZkL5PSixOt6ZNKm+w+Hfp/Bciwow==

fs-extra@^10.0.0:
version "10.0.0"
resolved "https://registry.yarnpkg.com/fs-extra/-/fs-extra-10.0.0.tgz#9ff61b655dde53fb34a82df84bb214ce802e17c1"
Expand Down Expand Up @@ -8583,7 +8605,7 @@ https-browserify@^1.0.0:
resolved "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz"
integrity sha1-7AbBDgo0wPL68Zn3/X/Hj//QPHM=

https-proxy-agent@^5.0.0:
https-proxy-agent@5.0.0, https-proxy-agent@^5.0.0:
version "5.0.0"
resolved "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.0.tgz"
integrity sha512-EkYm5BcKUGiduxzSt3Eppko+PiNWNEpa4ySk9vTC6wDsQJW9rHSa+UhGNJoRYp7bz6Ht1eaRIa6QaJqO5rCFbA==
Expand Down Expand Up @@ -11221,6 +11243,13 @@ node-fetch@*:
data-uri-to-buffer "^3.0.1"
fetch-blob "^3.1.2"

[email protected]:
version "2.6.7"
resolved "https://registry.yarnpkg.com/node-fetch/-/node-fetch-2.6.7.tgz#24de9fba827e3b4ae44dc8b20256a379160052ad"
integrity sha512-ZjMPFEfVx5j+y2yF35Kzx5sF7kDzxuDj6ziH4FFbOp87zKDZNx8yExJIb05OGF4Nlt9IHFIMBkRl41VdvcNdbQ==
dependencies:
whatwg-url "^5.0.0"

node-fetch@^1.0.1:
version "1.7.3"
resolved "https://registry.npmjs.org/node-fetch/-/node-fetch-1.7.3.tgz"
Expand Down Expand Up @@ -12285,7 +12314,7 @@ pkg-conf@^2.1.0:
find-up "^2.0.0"
load-json-file "^4.0.0"

pkg-dir@^4.1.0, pkg-dir@^4.2.0:
pkg-dir@4.2.0, pkg-dir@^4.1.0, pkg-dir@^4.2.0:
version "4.2.0"
resolved "https://registry.npmjs.org/pkg-dir/-/pkg-dir-4.2.0.tgz"
integrity sha512-HRDzbaKjC+AOWVXxAU/x54COGeIv9eb+6CkDSQoNTt4XyWoIJvuPsXizxu/Fr23EiekbtZwmh1IcIG/l/a10GQ==
Expand Down Expand Up @@ -12710,6 +12739,11 @@ process@~0.11.0:
resolved "https://registry.npmjs.org/process/-/process-0.11.10.tgz"
integrity sha1-czIwDoQBYb2j5podHZGn1LwW8YI=

[email protected]:
version "2.0.3"
resolved "https://registry.yarnpkg.com/progress/-/progress-2.0.3.tgz#7e8cf8d8f5b8f239c1bc68beb4eb78567d572ef8"
integrity sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==

promise-all-reject-late@^1.0.0:
version "1.0.1"
resolved "https://registry.npmjs.org/promise-all-reject-late/-/promise-all-reject-late-1.0.1.tgz"
Expand Down Expand Up @@ -12788,6 +12822,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.0.0.tgz#33c50398f70ea7eb96d21f7b817630a55791c7ee"
integrity sha1-M8UDmPcOp+uW0h97gXYwpVeRx+4=

[email protected]:
version "1.1.0"
resolved "https://registry.yarnpkg.com/proxy-from-env/-/proxy-from-env-1.1.0.tgz#e102f16ca355424865755d2c9e8ea4f24d58c3e2"
integrity sha512-D+zkORCbA9f1tdWRK0RaCR3GPv50cMxcrz4X8k5LTSUD1Dkw47mKJEZQNunItRTkWwgtaUSo1RVFRIG9ZXiFYg==

psl@^1.1.28, psl@^1.1.33:
version "1.8.0"
resolved "https://registry.npmjs.org/psl/-/psl-1.8.0.tgz"
Expand Down Expand Up @@ -12857,6 +12896,24 @@ pupa@^2.1.1:
dependencies:
escape-goat "^2.0.0"

[email protected]:
version "13.5.1"
resolved "https://registry.yarnpkg.com/puppeteer/-/puppeteer-13.5.1.tgz#d0f751bf36120efc2ebf74c7562a204a84e500e9"
integrity sha512-wWxO//vMiqxlvuzHMAJ0pRJeDHvDtM7DQpW1GKdStz2nZo2G42kOXBDgkmQ+zqjwMCFofKGesBeeKxIkX9BO+w==
dependencies:
cross-fetch "3.1.5"
debug "4.3.3"
devtools-protocol "0.0.969999"
extract-zip "2.0.1"
https-proxy-agent "5.0.0"
pkg-dir "4.2.0"
progress "2.0.3"
proxy-from-env "1.1.0"
rimraf "3.0.2"
tar-fs "2.1.1"
unbzip2-stream "1.4.3"
ws "8.5.0"

q@^1.5.1:
version "1.5.1"
resolved "https://registry.npmjs.org/q/-/q-1.5.1.tgz"
Expand Down Expand Up @@ -13146,7 +13203,7 @@ read@1, read@^1.0.7, read@~1.0.1, read@~1.0.7:
dependencies:
mute-stream "~0.0.4"

readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0:
readable-stream@3, readable-stream@^3.0.0, readable-stream@^3.1.1, readable-stream@^3.4.0, readable-stream@^3.5.0, readable-stream@^3.6.0:
version "3.6.0"
resolved "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.0.tgz"
integrity sha512-BViHy7LKeTz4oNnkcLJ+lVSL6vpiFeX6/d3oSH8zCW7UxP2onchk+vTGB143xuFjHS3deTgkKoXXymXqymiIdA==
Expand Down Expand Up @@ -14648,6 +14705,27 @@ table@^6.7.5:
string-width "^4.2.3"
strip-ansi "^6.0.1"

[email protected]:
version "2.1.1"
resolved "https://registry.yarnpkg.com/tar-fs/-/tar-fs-2.1.1.tgz#489a15ab85f1f0befabb370b7de4f9eb5cbe8784"
integrity sha512-V0r2Y9scmbDRLCNex/+hYzvp/zyYjvFbHPNgVTKfQvVrb6guiE/fxP+XblDNR011utopbkex2nM4dHNV6GDsng==
dependencies:
chownr "^1.1.1"
mkdirp-classic "^0.5.2"
pump "^3.0.0"
tar-stream "^2.1.4"

tar-stream@^2.1.4:
version "2.2.0"
resolved "https://registry.yarnpkg.com/tar-stream/-/tar-stream-2.2.0.tgz#acad84c284136b060dc3faa64474aa9aebd77287"
integrity sha512-ujeqbceABgwMZxEJnk2HDY2DlnUZ+9oEcb1KzTVfYHio0UE6dG71n60d8D2I4qNvleWrrXpmjpt7vZeF1LnMZQ==
dependencies:
bl "^4.0.3"
end-of-stream "^1.4.1"
fs-constants "^1.0.0"
inherits "^2.0.3"
readable-stream "^3.1.1"

tar@^6.0.2, tar@^6.1.0:
version "6.1.0"
resolved "https://registry.npmjs.org/tar/-/tar-6.1.0.tgz"
Expand Down Expand Up @@ -14905,6 +14983,11 @@ tr46@^2.1.0:
dependencies:
punycode "^2.1.1"

tr46@~0.0.3:
version "0.0.3"
resolved "https://registry.yarnpkg.com/tr46/-/tr46-0.0.3.tgz#8184fd347dac9cdc185992f3a6622e14b9d9ab6a"
integrity sha1-gYT9NH2snNwYWZLzpmIuFLnZq2o=

traverse@~0.6.6:
version "0.6.6"
resolved "https://registry.npmjs.org/traverse/-/traverse-0.6.6.tgz"
Expand Down Expand Up @@ -15110,6 +15193,14 @@ unbox-primitive@^1.0.1:
has-symbols "^1.0.2"
which-boxed-primitive "^1.0.2"

[email protected]:
version "1.4.3"
resolved "https://registry.yarnpkg.com/unbzip2-stream/-/unbzip2-stream-1.4.3.tgz#b0da04c4371311df771cdc215e87f2130991ace7"
integrity sha512-mlExGW4w71ebDJviH16lQLtZS32VKqsSfk80GCfUlwT/4/hNRFsoscrF/c++9xinkMzECL1uL9DDwXqFWkruPg==
dependencies:
buffer "^5.2.1"
through "^2.3.8"

unc-path-regex@^0.1.2:
version "0.1.2"
resolved "https://registry.npmjs.org/unc-path-regex/-/unc-path-regex-0.1.2.tgz"
Expand Down Expand Up @@ -15543,6 +15634,11 @@ [email protected]:
resolved "https://registry.yarnpkg.com/web-vitals/-/web-vitals-2.1.2.tgz#3a6c8faebf9097a6ccd17f5f45c9485d8d62dab1"
integrity sha512-nZnEH8dj+vJFqCRYdvYv0a59iLXsb8jJkt+xvXfwgnkyPdsSLtKNlYmtTDiHmTNGXeSXtpjTTUcNvFtrAk6VMQ==

webidl-conversions@^3.0.0:
version "3.0.1"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-3.0.1.tgz#24534275e2a7bc6be7bc86611cc16ae0a5654871"
integrity sha1-JFNCdeKnvGvnvIZhHMFq4KVlSHE=

webidl-conversions@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/webidl-conversions/-/webidl-conversions-5.0.0.tgz#ae59c8a00b121543a2acc65c0434f57b0fc11aff"
Expand Down Expand Up @@ -15570,6 +15666,14 @@ whatwg-mimetype@^2.3.0:
resolved "https://registry.yarnpkg.com/whatwg-mimetype/-/whatwg-mimetype-2.3.0.tgz#3d4b1e0312d2079879f826aff18dbeeca5960fbf"
integrity sha512-M4yMwr6mAnQz76TbJm914+gPpB/nCwvZbJU28cUD6dR004SAxDLOOSUaB1JDRqLtaOV/vi0IC5lEAGFgrjGv/g==

whatwg-url@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-5.0.0.tgz#966454e8765462e37644d3626f6742ce8b70965d"
integrity sha1-lmRU6HZUYuN2RNNib2dCzotwll0=
dependencies:
tr46 "~0.0.3"
webidl-conversions "^3.0.0"

whatwg-url@^8.0.0, whatwg-url@^8.5.0:
version "8.7.0"
resolved "https://registry.yarnpkg.com/whatwg-url/-/whatwg-url-8.7.0.tgz#656a78e510ff8f3937bc0bcbe9f5c0ac35941b77"
Expand Down Expand Up @@ -15678,6 +15782,11 @@ write-file-atomic@^3.0.0, write-file-atomic@^3.0.3:
signal-exit "^3.0.2"
typedarray-to-buffer "^3.1.5"

[email protected]:
version "8.5.0"
resolved "https://registry.yarnpkg.com/ws/-/ws-8.5.0.tgz#bfb4be96600757fe5382de12c670dab984a1ed4f"
integrity sha512-BWX0SWVgLPzYwF8lTzEy1egjhS4S4OEAHfsO8o65WOVsrnSRGaSiUaa9e0ggGlkMTtBlmOpEXiie9RUcBO86qg==

ws@^7.4.6:
version "7.5.7"
resolved "https://registry.yarnpkg.com/ws/-/ws-7.5.7.tgz#9e0ac77ee50af70d58326ecff7e85eb3fa375e67"
Expand Down

0 comments on commit d4a784a

Please sign in to comment.