Skip to content

Commit

Permalink
v
Browse files Browse the repository at this point in the history
  • Loading branch information
Seroxdesign committed Jun 24, 2024
1 parent 850b037 commit 7991b42
Show file tree
Hide file tree
Showing 15 changed files with 32 additions and 27 deletions.
11 changes: 7 additions & 4 deletions packages/cache/test/createCache.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'

import path from 'node:path'
import * as GetUniqueWalletSetupFunctions from '@synthetixio/synpress-utils'
import * as TriggerCacheCreation from '@synthetixio/synpress-utils'
import type { BrowserContext, Page } from 'playwright-core'
import { createCache } from '../src/createCache'
import type { WalletSetupFunction } from '../src/defineWalletSetup'
import * as GetUniqueWalletSetupFunctions from '../src/utils/getUniqueWalletSetupFunctions'
import * as TriggerCacheCreation from '../src/utils/triggerCacheCreation'

const ROOT_DIR = '/tmp'

const setupFunctions = new Map<string, { fileName: string; setupFunction: WalletSetupFunction }>()
const setupFunctions = new Map<
string,
{ fileName: string; setupFunction: (context: BrowserContext, walletPage: Page) => Promise<void> }
>()

setupFunctions.set('hash1', { fileName: path.join(ROOT_DIR, 'hash1'), setupFunction: vi.fn() })
setupFunctions.set('hash2', { fileName: path.join(ROOT_DIR, 'hash2'), setupFunction: vi.fn() })
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/downloadFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import path from 'node:path'
import { downloadFile } from '@synthetixio/synpress-utils'
import axios from 'axios'
import { fs, vol } from 'memfs'
import { http, HttpResponse } from 'msw'
import { setupServer } from 'msw/node'
import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest'
import { downloadFile } from '../src'

const ROOT_DIR = '/tmp'
const FILE_NAME = 'duck.txt'
Expand Down
4 changes: 2 additions & 2 deletions packages/cache/test/ensureCacheDirExists.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import path from 'node:path'
import { CACHE_DIR_NAME } from '@synthetixio/synpress-utils'
import { ensureCacheDirExists } from '@synthetixio/synpress-utils'
import fs from 'fs-extra'
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
import { CACHE_DIR_NAME } from '../src/constants'
import { ensureCacheDirExists } from '../src/ensureCacheDirExists'

vi.mock('fs-extra', async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/unzipArchive.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { unzipArchive } from '@synthetixio/synpress-utils'
import { fs, vol } from 'memfs'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { unzipArchive } from '../src/unzipArchive'
import {
ARCHIVE_CONTENTS,
createTestZipArchive,
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/bytesToMegabytes.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { bytesToMegabytes } from '@synthetixio/synpress-utils'
import { describe, expect, it } from 'vitest'
import { bytesToMegabytes } from '../../src/utils/bytesToMegabytes'

describe('bytesToMegabytes', () => {
it('converts bytes to megabytes and rounds the result', async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createCacheForWalletSetupFunction } from '@synthetixio/synpress-utils'
import * as WaitForExtensionOnLoadPage from '@synthetixio/synpress-utils'
import { chromium } from 'playwright-core'
import { afterAll, afterEach, beforeAll, describe, expect, it, vi } from 'vitest'
import { createCacheForWalletSetupFunction } from '../../src/utils/createCacheForWalletSetupFunction'
import * as WaitForExtensionOnLoadPage from '../../src/utils/waitForExtensionOnLoadPage'

const EXTENSION_PATH = '/tmp/extension'
const CONTEXT_PATH = '/tmp/context'
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/createTempContextDir.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import os from 'node:os'
import path from 'node:path'
import { createTempContextDir } from '@synthetixio/synpress-utils'
import { fs, vol } from 'memfs'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { createTempContextDir } from '../../src/utils/createTempContextDir'

const BROWSER_NAME = 'chromium'
const TEST_ID = 'test-id'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getUniqueWalletSetupFunctions } from '@synthetixio/synpress-utils'
import { afterAll, describe, expect, it, vi } from 'vitest'
import { getUniqueWalletSetupFunctions } from '../../src/utils/getUniqueWalletSetupFunctions'

vi.mock('../../src/utils/getWalletSetupFiles', async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/getWalletSetupFiles.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { getWalletSetupFiles } from '@synthetixio/synpress-utils'
import { fs, vol } from 'memfs'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { getWalletSetupFiles } from '../../src/utils/getWalletSetupFiles'

const ROOT_DIR = '/tmp'
const DUMMY_CONTENT = 'Hello world! 👋'
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/getWalletSetupFuncHash.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { WALLET_SETUP_FUNC_HASH_LENGTH, getWalletSetupFuncHash } from '@synthetixio/synpress-utils'
import { describe, expect, it } from 'vitest'
import { WALLET_SETUP_FUNC_HASH_LENGTH, getWalletSetupFuncHash } from '../../src/utils/getWalletSetupFuncHash'

const EXPECTED_HASH = 'b940c886be3c1a041ddd'

Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/importWalletSetupFile.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { importWalletSetupFile } from '@synthetixio/synpress-utils'
import { afterAll, describe, expect, it, vi } from 'vitest'
import { importWalletSetupFile } from '../../src/utils/importWalletSetupFile'

vi.mock('../../src/ensureCacheDirExists', async () => {
return {
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/isDirEmpty.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import path from 'node:path'
import { isDirEmpty } from '@synthetixio/synpress-utils'
import { fs, vol } from 'memfs'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
import { isDirEmpty } from '../../src/utils/isDirEmpty'

const ROOT_DIR = '/tmp'
const FILE_PATH = path.join(ROOT_DIR, 'file.txt')
Expand Down
2 changes: 1 addition & 1 deletion packages/cache/test/utils/removeTempContextDir.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { removeTempContextDir } from '@synthetixio/synpress-utils'
import { afterAll, describe, expect, it, vi } from 'vitest'
import { removeTempContextDir } from '../../src/utils/removeTempContextDir'

const PATH = 'Happy Quack Path'
const MAX_RETRIES = 10
Expand Down
18 changes: 10 additions & 8 deletions packages/cache/test/utils/triggerCacheCreation.test.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { fs, vol } from 'memfs'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

import path from 'node:path'
import * as EnsureCacheDirExists from '@synthetixio/synpress-utils'
import * as CreateCacheForWalletSetupFunction from '@synthetixio/synpress-utils'
import { triggerCacheCreation } from '@synthetixio/synpress-utils'
import fsExtra from 'fs-extra'
import type { WalletSetupFunction } from '../../src'
import * as EnsureCacheDirExists from '../../src/ensureCacheDirExists'
import * as CreateCacheForWalletSetupFunction from '../../src/utils/createCacheForWalletSetupFunction'
import { triggerCacheCreation } from '../../src/utils/triggerCacheCreation'
import { fs, vol } from 'memfs'
import type { BrowserContext, Page } from 'playwright-core'
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from 'vitest'

const ROOT_DIR = '/tmp'
const EXTENSION_PATH = path.join(ROOT_DIR, 'extension')
Expand Down Expand Up @@ -58,7 +57,10 @@ describe('triggerCacheCreation', () => {
const testSetupFunction = vi.fn()

function prepareSetupFunctions(hashes: string[]) {
const setupFunctions = new Map<string, { fileName: string; setupFunction: WalletSetupFunction }>()
const setupFunctions = new Map<
string,
{ fileName: string; setupFunction: (context: BrowserContext, walletPage: Page) => Promise<void> }
>()

for (const hash of hashes) {
setupFunctions.set(hash, { fileName: path.join(ROOT_DIR, `${hash}.ts`), setupFunction: testSetupFunction })
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { waitForExtensionOnLoadPage } from '@synthetixio/synpress-utils'
import { errors as playwrightErrors } from 'playwright-core'
import { afterAll, afterEach, describe, expect, it, vi } from 'vitest'
import { waitForExtensionOnLoadPage } from '../../src/utils/waitForExtensionOnLoadPage'

const createContext = vi.fn().mockReturnValue({
waitForEvent: vi.fn().mockResolvedValue(undefined)
Expand Down

0 comments on commit 7991b42

Please sign in to comment.