Skip to content

Commit

Permalink
🎨 style: Use line width of 120 characters
Browse files Browse the repository at this point in the history
  • Loading branch information
duckception committed Oct 5, 2023
1 parent 70cc430 commit f499afa
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 71 deletions.
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
]
},
"formatter": {
"lineWidth": 120,
"indentStyle": "space",
"indentSize": 2
},
Expand Down
5 changes: 1 addition & 4 deletions examples/metamask-legacy/src/example.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import { helpers, metamask, metamaskPages } from 'metamask-legacy'

console.log('Current network:', helpers.getCurrentNetwork())
console.log(
'Example selector:',
metamaskPages.mainPage.mainPageElements.importAccount.importButton
)
console.log('Example selector:', metamaskPages.mainPage.mainPageElements.importAccount.importButton)
console.log('MetaMask extension urls:', metamask.extensionUrls())
4 changes: 1 addition & 3 deletions packages/core/src/downloadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ export async function downloadFile(options: DownloaderOptions) {

// TODO: This is a workaround to handle errors from both `writer` and `axios` and get 100% test coverage.
return returnPromise.catch((error: Error) => {
throw new Error(
`[DownloadFile] Error downloading the file - ${error.message}`
)
throw new Error(`[DownloadFile] Error downloading the file - ${error.message}`)
})
}
20 changes: 3 additions & 17 deletions packages/core/test/downloadFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@ import axios from 'axios'
import { fs, vol } from 'memfs'
import { rest } from 'msw'
import { setupServer } from 'msw/node'
import {
afterAll,
afterEach,
beforeAll,
beforeEach,
describe,
expect,
it,
vi
} from 'vitest'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { downloadFile } from '../src/downloadFile'

const ROOT_DIR = '/tmp'
Expand Down Expand Up @@ -71,10 +62,7 @@ describe('downloadFile', () => {
it('throws an error if the file cannot be downloaded', async () => {
server.use(
rest.get(MOCK_URL, (_, res, ctx) => {
return res(
ctx.status(500),
ctx.json({ message: 'Internal server error' })
)
return res(ctx.status(500), ctx.json({ message: 'Internal server error' }))
})
)

Expand Down Expand Up @@ -128,9 +116,7 @@ describe('downloadFile', () => {
downloadSkipped: true
})
expect(fs.existsSync(result.filePath)).toBe(true)
expect(fs.readFileSync(result.filePath, 'utf8')).toBe(
existingMockFileContent
)
expect(fs.readFileSync(result.filePath, 'utf8')).toBe(existingMockFileContent)

expect(axiosGetSpy).not.toHaveBeenCalled()
})
Expand Down
35 changes: 7 additions & 28 deletions packages/core/test/unzipArchive.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import path from 'node:path'
import { fs, vol } from 'memfs'
import {
afterAll,
afterEach,
beforeEach,
describe,
expect,
it,
vi
} from 'vitest'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { unzipArchive } from '../src/unzipArchive'
import {
ARCHIVE_CONTENTS,
Expand All @@ -23,10 +15,7 @@ const ARCHIVE_PATH = path.join(ROOT_DIR, 'archive.zip')
const OUTPUT_PATH = path.join(ROOT_DIR, 'archive')
const OUTPUT_NESTED_DIR_PATH = path.join(OUTPUT_PATH, 'nested')
const FILE_OUTPUT_PATH = path.join(OUTPUT_PATH, FILE_NAME)
const NESTED_FILE_OUTPUT_PATH = path.join(
OUTPUT_NESTED_DIR_PATH,
NESTED_FILE_NAME
)
const NESTED_FILE_OUTPUT_PATH = path.join(OUTPUT_NESTED_DIR_PATH, NESTED_FILE_NAME)

vi.mock('fs-extra', async () => {
return {
Expand Down Expand Up @@ -88,12 +77,8 @@ describe('unzipArchive', () => {
unzipSkipped: false
})
expect(fs.existsSync(result.outputPath)).toBe(true)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).toBe(
ARCHIVE_CONTENTS[FILE_NAME]
)
expect(fs.readFileSync(NESTED_FILE_OUTPUT_PATH, 'utf8')).toBe(
ARCHIVE_CONTENTS[NESTED_FILE_NAME]
)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).toBe(ARCHIVE_CONTENTS[FILE_NAME])
expect(fs.readFileSync(NESTED_FILE_OUTPUT_PATH, 'utf8')).toBe(ARCHIVE_CONTENTS[NESTED_FILE_NAME])
}

it('unzips the archive', async () => {
Expand Down Expand Up @@ -132,9 +117,7 @@ describe('unzipArchive', () => {
unzipSkipped: true
})
expect(fs.existsSync(FILE_OUTPUT_PATH)).toBe(true)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).toBe(
unzippedFileContent
)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).toBe(unzippedFileContent)

expect(createReadStreamSpy).not.toHaveBeenCalled()
})
Expand All @@ -152,12 +135,8 @@ describe('unzipArchive', () => {
unzipSkipped: false
})
expect(fs.existsSync(result.outputPath)).toBe(true)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).not.toBe(
unzippedFileContent
)
expect(fs.readFileSync(NESTED_FILE_OUTPUT_PATH, 'utf8')).toBe(
ARCHIVE_CONTENTS[NESTED_FILE_NAME]
)
expect(fs.readFileSync(FILE_OUTPUT_PATH, 'utf8')).not.toBe(unzippedFileContent)
expect(fs.readFileSync(NESTED_FILE_OUTPUT_PATH, 'utf8')).toBe(ARCHIVE_CONTENTS[NESTED_FILE_NAME])
})
})
})
9 changes: 2 additions & 7 deletions packages/core/test/utils/createTestZipArchive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,10 @@ export const ARCHIVE_CONTENTS = {
export function createTestZipArchive(archivePath: string) {
const targetDir = path.dirname(archivePath)
fs.mkdirSync(targetDir, { recursive: true })
fs.writeFileSync(
archivePath,
Buffer.from(ZIP_ARCHIVE_CONTENT_IN_BASE_64_URL, 'base64url')
)
fs.writeFileSync(archivePath, Buffer.from(ZIP_ARCHIVE_CONTENT_IN_BASE_64_URL, 'base64url'))
}

export async function createTestZipArchiveWithIncorrectEntries(
archivePath: string
) {
export async function createTestZipArchiveWithIncorrectEntries(archivePath: string) {
return new Promise<void>((resolve, reject) => {
const archiveStream = fs.createWriteStream(archivePath)
const archive = archiver('zip', {
Expand Down
9 changes: 2 additions & 7 deletions wallets/metamask/test/e2e/prepareExtension.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,7 @@ const test = base.extend({
context: async ({ context: _ }, use) => {
const metamaskPath = await prepareExtension()

const browserArgs = [
`--disable-extensions-except=${metamaskPath}`,
`--load-extension=${metamaskPath}`
]
const browserArgs = [`--disable-extensions-except=${metamaskPath}`, `--load-extension=${metamaskPath}`]

if (process.env.HEADLESS) {
browserArgs.push('--headless=new')
Expand Down Expand Up @@ -38,8 +35,6 @@ const { describe, expect } = test
describe('prepareExtension', () => {
test('onboarding page opens up', async ({ page }) => {
await expect(page).toHaveTitle('MetaMask')
await expect(
page.getByRole('heading', { name: "Let's get started" })
).toBeVisible()
await expect(page.getByRole('heading', { name: "Let's get started" })).toBeVisible()
})
})
6 changes: 1 addition & 5 deletions wallets/metamask/test/unit/prepareExtension.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
import * as core from 'core'
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
import {
DEFAULT_METAMASK_VERSION,
EXTENSION_DOWNLOAD_URL,
prepareExtension
} from '../../src/prepareExtension'
import { DEFAULT_METAMASK_VERSION, EXTENSION_DOWNLOAD_URL, prepareExtension } from '../../src/prepareExtension'

const MOCK_CACHE_DIR_PATH = 'mockCacheDirPath'
const MOCK_EXTENSION_ARCHIVE_PATH = 'mockExtensionArchivePath'
Expand Down

0 comments on commit f499afa

Please sign in to comment.