Skip to content
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

Merged
merged 14 commits into from
Nov 21, 2022
Merged

Conversation

whizzzkid
Copy link
Contributor

@whizzzkid whizzzkid commented Oct 22, 2022

Enhances #1054

In this PR:

  • I am replacing require with import/export
  • Upgrading even more packages.
  • Fixing webExt missing config
  • Replacing nyc with c8

Copy link
Contributor Author

@whizzzkid whizzzkid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explainers

package.json Outdated Show resolved Hide resolved
global.chrome = browser
global.navigator = {
clipboard: {
writeText: () => {}
Copy link
Contributor Author

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.

Copy link
Member

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?

@whizzzkid whizzzkid force-pushed the fix/refactor/necromancy branch from 47e50b6 to 4f3cab1 Compare October 26, 2022 15:20
@whizzzkid whizzzkid marked this pull request as ready for review October 26, 2022 16:26
@whizzzkid whizzzkid requested review from lidel, meandavejustice and a team as code owners October 26, 2022 16:26
Copy link
Contributor Author

@whizzzkid whizzzkid left a 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()
Copy link
Contributor Author

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\"",
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

package.json Outdated
Comment on lines 66 to 75
"c8": {
"all": true,
"reporter": [
"lcov",
"text"
],
"include": [
"add-on/src/**"
]
},
Copy link
Contributor Author

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

Comment on lines +3 to +8
// 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'
Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Member

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) {
Copy link
Contributor Author

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'
Copy link
Contributor Author

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.

@whizzzkid
Copy link
Contributor Author

@lidel bringing this up again for your consideration! ❤️

Copy link
Collaborator

@meandavejustice meandavejustice left a 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

Comment on lines +3 to +8
// 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'
Copy link
Collaborator

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'
Copy link
Collaborator

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.

Copy link
Member

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

package.json Outdated Show resolved Hide resolved
Copy link
Member

@lidel lidel left a 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.

@lidel lidel changed the title Fix refactor/necromancy refactor: working necromancy tests Nov 16, 2022
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
Copy link
Member

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.

Comment on lines +4 to +10
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'
Copy link
Member

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):

  1. stdlib imports;
  2. 3p imports;
  3. 2p imports (internal to company but not to team)
  4. 1p imports (internal to team)
  5. local/relative imports (internal to project)

eslint-plugin-imports allows you to automate this

Comment on lines +18 to 20
export async function destroy (browser) {
log('destroy')
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove / delete?

Comment on lines 21 to +25
gatewayAddress,
gatewayVersion,
swarmPeers,
ipfsNodeType
ipfsApiUrl,
ipfsNodeType,
swarmPeers
Copy link
Member

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.

package.json Outdated Show resolved Hide resolved
import { expect } from 'chai'
import { URL } from 'url'
import sinon from 'sinon'
import createDnslinkResolver from '../../../add-on/src/lib/dnslink.js'
Copy link
Member

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: () => {}
Copy link
Member

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'
Copy link
Member

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?

test/helpers/acl.js Outdated Show resolved Hide resolved
Copy link
Member

@lidel lidel left a 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.

@lidel lidel merged commit a848969 into refactor/necromancy Nov 21, 2022
@lidel lidel deleted the fix/refactor/necromancy branch November 21, 2022 18:54
lidel added a commit that referenced this pull request Nov 22, 2022
- 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants