-
Notifications
You must be signed in to change notification settings - Fork 325
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: working necromancy tests #1101
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
explainers
global.chrome = browser | ||
global.navigator = { | ||
clipboard: { | ||
writeText: () => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was something extra I had to add to prevent dependency from failing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which dependency? Can we add a comment to the code to call it out? Do we need that dependency?
47e50b6
to
4f3cab1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
more explainers.
} | ||
// We need to do this because global is not mapped otherwise, we need to stub browser and chrome runtime | ||
// so that the webextension-polyfill does not complain about the test runner not being a browser instance. | ||
const init = async () => (await import('../../../add-on/src/lib/ipfs-companion.js')).default() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this was really the problem I had to solve because how node's module resolution works. stubbing global.browser
was not possible when import
for a module is called.
However doing it this way allows us to pass in stubbed references.
@@ -37,7 +38,7 @@ | |||
"watch:js": "run-p watch:js:*", | |||
"watch:js:webpack": "webpack --watch --mode development --devtool inline-source-map --config ./webpack.config.js", | |||
"test": "run-s test:*", | |||
"test:functional": " nyc --reporter=lcov --reporter=text mocha --timeout 15000 --require ignore-styles \"test/functional/**/*.test.js\"", | |||
"test:functional": "c8 mocha --timeout 5000 --require ignore-styles \"test/functional/**/*.test.js\"", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
c8
is a drop-in replacement for nyc
. nyc
fails with ESM on Node > 16.12. Src:
package.json
Outdated
"c8": { | ||
"all": true, | ||
"reporter": [ | ||
"lcov", | ||
"text" | ||
], | ||
"include": [ | ||
"add-on/src/**" | ||
] | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
moving configs like so instead of flags
// import CID from 'cids' | ||
|
||
// const Tar = require('it-tar') | ||
// const pipe = require('it-pipe') | ||
// const all = require('it-all') | ||
// const concat = require('it-concat') | ||
// import Tar from 'it-tar' | ||
// import pipe from 'it-pipe' | ||
// import all from 'it-all' | ||
// import concat from 'it-concat' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need these? this got replaced as part of the regex match.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like they are all for "downloading CID from public gateway". It's commented out code so I would say it's good to be removed. It's in git history if you ever want to reference it. But @lidel may have more insight
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, this is legacy code that needs to be replaced – filled #1102 so it is not blocking necromancy PRs ;)
@@ -1,6 +1,6 @@ | |||
'use strict' | |||
|
|||
function createProxyAccessDialogStore (i18n, runtime) { | |||
export default function createProxyAccessDialogStore (_i18n, runtime) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to make the editor happy, we are not using this.
@@ -1,9 +1,9 @@ | |||
'use strict' | |||
|
|||
const isIP = require('is-ip') | |||
const isFQDN = require('is-fqdn') | |||
import { isIPv4, isIPv6 } from 'is-ip' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isIP@4 has this breaking change.
@lidel bringing this up again for your consideration! ❤️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Left a couple comments since I was here
// import CID from 'cids' | ||
|
||
// const Tar = require('it-tar') | ||
// const pipe = require('it-pipe') | ||
// const all = require('it-all') | ||
// const concat = require('it-concat') | ||
// import Tar from 'it-tar' | ||
// import pipe from 'it-pipe' | ||
// import all from 'it-all' | ||
// import concat from 'it-concat' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like they are all for "downloading CID from public gateway". It's commented out code so I would say it's good to be removed. It's in git history if you ever want to reference it. But @lidel may have more insight
import { expect } from 'chai' | ||
import { URL } from 'url' | ||
import sinon from 'sinon' | ||
import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NIT: .js
shouldn't be necessary for these imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should standardize on esm imports and the .js
extension is part of the filename. We should be consistent even if there is tooling that does "magic" for us. Open to hearing your thoughts @meandavejustice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll try to block some time this week to review this properly (there are some manual tests around Brave onboarding which I need to go over + document in ./docs
).
For now, dropped quick comments above.
exports.tickMs = 250 // no CPU spike, but still responsive enough | ||
export const welcomePage = '/dist/landing-pages/welcome/index.html' | ||
export const optionsPage = '/dist/options/options.html' | ||
export const tickMs = 250 // no CPU spike, but still responsive enough |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would love a JSdoc comment on this to explain its intention. I can guess, but it's better if we don't force others to.
import Pqueue from 'p-queue' | ||
|
||
import debug from 'debug' | ||
import IsIpfs from 'is-ipfs' | ||
import LRU from 'lru-cache' | ||
import { offlinePeerCount } from './state.js' | ||
import { ipfsContentPath, sameGateway, pathAtHttpGateway } from './ipfs-path.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spacing - I personally prefer organizing imports in four (potentially 5 groups depending on how large your 1st party import sections are):
- stdlib imports;
- 3p imports;
- 2p imports (internal to company but not to team)
- 1p imports (internal to team)
- local/relative imports (internal to project)
eslint-plugin-imports allows you to automate this
export async function destroy (browser) { | ||
log('destroy') | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove / delete?
gatewayAddress, | ||
gatewayVersion, | ||
swarmPeers, | ||
ipfsNodeType | ||
ipfsApiUrl, | ||
ipfsNodeType, | ||
swarmPeers |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you're alphabetizing things like this manually, stop and wait for eslint automation. I prefer organized keys and imports as well, but they will quickly get out of date without a 'fixable' eslint rule.
import { expect } from 'chai' | ||
import { URL } from 'url' | ||
import sinon from 'sinon' | ||
import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we should standardize on esm imports and the .js
extension is part of the filename. We should be consistent even if there is tooling that does "magic" for us. Open to hearing your thoughts @meandavejustice
global.chrome = browser | ||
global.navigator = { | ||
clipboard: { | ||
writeText: () => {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
which dependency? Can we add a comment to the code to call it out? Do we need that dependency?
@@ -27,6 +27,7 @@ describe('modifyRequest processing of DNSLinks', function () { | |||
before(function () { | |||
global.URL = URL | |||
global.browser = browser | |||
browser.runtime.id = 'testid' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're using the same id for browser.runtime.id
in multiple tests. What is browser.runtime.id
used for, and would it aid in test debugging to provide a different id?
Can we set the id to this.testName
or similar?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you @whizzzkid.
In effort to unblock general Companion work I'm merging, let's continue in #1054 and/or separate PRs.
- removed yarn and all the hackery around transitive dependency overrides - bumped all dependencies - switched to ipfs-core for less deps - removed unused deps - firefox manifest fix to pass latest webext lint - removed remaining window.ipfs code that was pulling dead dependencies (ipfs/in-web-browsers#172) - fixed tests (#1101) - and much more Co-authored-by: Nishant Arora <1895906+whizzzkid@users.noreply.github.com>
Enhances #1054
In this PR:
require
withimport
/export
webExt
missing confignyc
withc8