diff --git a/packages/node/test/unit/ConfigWizard.test.ts b/packages/node/test/unit/ConfigWizard.test.ts index 9d2e18961c..539595b4a7 100644 --- a/packages/node/test/unit/ConfigWizard.test.ts +++ b/packages/node/test/unit/ConfigWizard.test.ts @@ -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' @@ -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') @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => { @@ -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 () => {