Skip to content

Commit

Permalink
test(node): Fix config wizard storage path tests (#2906)
Browse files Browse the repository at this point in the history
Fixed config wizard storage path assertions to be compatible with Mac
OS. In the assertion we compare the real path to a symbolic link in Mac
OS and thererore the test fails.

## Change

Now compares normalized paths, i.e. uses `realpathSync` which resolves
symbolic links.

## Error

```
    expect(received).toInclude(expected)

    Expected string to include:
      "streamr-node /var/folders/_1/sztmfs_j15zg4t29k2nql0040000gn/T/test-config-wizardhSM4Wz/config.json
    "
    Received:
      "Welcome to the Streamr Network!
        This Config Wizard will help you setup your node.·····
        The steps are documented here:
        https://docs.streamr.network/guides/how-to-run-streamr-node#config-wizard
    ✓ Congratulations, you've setup your Streamr node!
        Your node address is 0x909DC59FF7A3b23126bc6F86ad44dD808fd424Dc
        Your node's generated name is Mountain Until Gun
    You can start your Streamr node now with
        streamr-node /var/folders/1/sztmfsj15zg4t29k2nql0040000gn/T/test-config-wizardhSM4Wz/config.json·····
        For environment specific run instructions, see
        https://docs.streamr.network/guides/how-to-run-streamr-node"

      158 |         expect(summary).toInclude(`generated name is Mountain Until Gun\n`)
      159 |
    > 160 |         expect(summary).toInclude(`streamr-node ${storagePath}\n`)
          |                         ^
      161 |     })
      162 |
      163 |     it('prints out the generated private key onto the screen if told to', async () => {

      at Object.<anonymous> (test/unit/ConfigWizard.test.ts:160:25)
```
  • Loading branch information
teogeb authored Dec 9, 2024
1 parent c5d8d27 commit eb6de91
Showing 1 changed file with 32 additions and 17 deletions.
49 changes: 32 additions & 17 deletions packages/node/test/unit/ConfigWizard.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { existsSync, mkdtempSync, readFileSync, writeFileSync } from 'fs'
import { existsSync, mkdtempSync, readFileSync, realpathSync, writeFileSync } from 'fs'
import os from 'os'
import path from 'path'
import { getNodeMnemonic, start } from '../../src/config/ConfigWizard'
Expand Down Expand Up @@ -78,10 +78,25 @@ const IMPORTED_PRIVATE_KEY =

const OPERATOR_ADDRESS = '0x54d68882d5329397928787ec496da3ba8e45c48c'

const extractStoragePath = (summary: string): string | undefined => {
const match = summary.match(/streamr-node ([^\s]w+)/)
return (match !== null) ? match[1] : undefined
}

const expectPathsEqual = (actual: string | undefined, expected: string): void => {
if (actual !== undefined) {
const normalizedActual = path.normalize(realpathSync(actual))
const normaliszedExpected = path.normalize(realpathSync(expected))
expect(normalizedActual).toEqual(normaliszedExpected)
} else {
expect.fail('Path is undefined')
}
}

describe('Config wizard', () => {
let tempDir = mkdtempSync(path.join(os.tmpdir(), 'test-config-wizard'))
let tempDir: string

let storagePath = path.join(tempDir, 'config.json')
let storagePath: string

const fakeBalance = jest.fn(() => '0.0')

Expand Down Expand Up @@ -157,7 +172,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('prints out the generated private key onto the screen if told to', async () => {
Expand Down Expand Up @@ -220,7 +235,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Flee Kit Stomach\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('validates given private key', async () => {
Expand Down Expand Up @@ -299,7 +314,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('validates the operator address', async () => {
Expand Down Expand Up @@ -387,7 +402,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables websocket plugin on a custom port', async () => {
Expand Down Expand Up @@ -445,7 +460,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables mqtt plugin on the default port', async () => {
Expand Down Expand Up @@ -507,7 +522,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables mqtt plugin on a custom port', async () => {
Expand Down Expand Up @@ -569,7 +584,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables http plugin on the default port', async () => {
Expand Down Expand Up @@ -632,7 +647,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables http plugin on a custom port', async () => {
Expand Down Expand Up @@ -693,7 +708,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables all pubsub plugins on default ports', async () => {
Expand Down Expand Up @@ -766,7 +781,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('enables all pubsub plugins on custom ports', async () => {
Expand Down Expand Up @@ -837,7 +852,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('validates port number values', async () => {
Expand Down Expand Up @@ -947,7 +962,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('disallows taking default ports if they are inexplicitly used', async () => {
Expand Down Expand Up @@ -1024,7 +1039,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('allows to uses a custom file path for the config file', async () => {
Expand Down Expand Up @@ -1234,7 +1249,7 @@ describe('Config wizard', () => {

expect(summary).toInclude(`generated name is Mountain Until Gun\n`)

expect(summary).toInclude(`streamr-node ${storagePath}\n`)
expectPathsEqual(extractStoragePath(summary), storagePath)
})

it('tells the user to fund their node address if the balance is too low', async () => {
Expand Down

0 comments on commit eb6de91

Please sign in to comment.