Skip to content

enabling "trust" authentication for local connections #26

@sydrawat01

Description

@sydrawat01

On following the documentation to use the jest-postgres package, I ran into the following error:

✗  yarn run test
yarn run v1.22.19
$ jest --passWithNoTests --runInBand --no-cache
Determining test suites to run...initdb: warning: enabling "trust" authentication for local connections
initdb: hint: You can change this by editing pg_hba.conf or using the option -A, or --auth-local and --auth-host, the next time you run initdb.
PostgresError: syntax error at or near "describe"
    at ErrorResponse (/Users/sid/Developer/clean-architecture/node_modules/@shelf/postgres-local/node_modules/postgres/cjs/src/connection.js:765:26)
    at handle (/Users/sid/Developer/clean-architecture/node_modules/@shelf/postgres-local/node_modules/postgres/cjs/src/connection.js:468:6)
    at Socket.data (/Users/sid/Developer/clean-architecture/node_modules/@shelf/postgres-local/node_modules/postgres/cjs/src/connection.js:312:9)
    at Socket.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:324:12)
    at readableAddChunk (node:internal/streams/readable:297:9)
    at Readable.push (node:internal/streams/readable:234:10)
    at TCP.onStreamRead (node:internal/stream_base_commons:190:23)
Error: Jest: Got error running globalSetup - /Users/sid/Developer/clean-architecture/node_modules/@shelf/jest-postgres/lib/setup.js, reason: [PostgresError: syntax error at or near "describe"]
    at runGlobalHook (/Users/sid/Developer/clean-architecture/node_modules/@jest/core/build/runGlobalHook.js:117:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async runJest (/Users/sid/Developer/clean-architecture/node_modules/@jest/core/build/runJest.js:327:5)
    at async _run10000 (/Users/sid/Developer/clean-architecture/node_modules/@jest/core/build/cli/index.js:344:7)
    at async runCLI (/Users/sid/Developer/clean-architecture/node_modules/@jest/core/build/cli/index.js:199:3)
    at async Object.run (/Users/sid/Developer/clean-architecture/node_modules/jest-cli/build/run.js:124:37)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

I did update my pg_hba.conf file under /opt/homebrew/var/postgresql@15 to include the following line:

host    all             all             0.0.0.0/0            md5

I restarted my server using brew services restart postgresql@15 and tried running my tests again, but it fails again.

jest-postgres-config.js :

/* eslint-disable*/
const cwd = require('cwd');

module.exports = {
  seedPath: `${cwd()}/test/test.spec.ts`,
  version: 14,
  port: 5555,
};

test/test.spec.ts:

describe('test', () => {
  it('should work', () => {
    expect(true).toBe(true)
  })
})

jest.config.js:

/* eslint-disable */

/**
 * For a detailed explanation regarding each configuration property, visit:
 * https://jestjs.io/docs/configuration
 */

const { defaults: tsjPreset } = require('ts-jest/presets');

/** @type {import('jest').Config} */
const config = {
  // An array of glob patterns indicating a set of files for which coverage information should be collected
  collectCoverageFrom: ['<rootDir>/src/**/*.ts', '!<rootDir>/src/main/**/*.ts'],

  // The directory where Jest should output its coverage files
  coverageDirectory: 'coverage',

  // Indicates which provider should be used to instrument code for coverage
  coverageProvider: 'v8',

  // A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
  moduleNameMapper: {
    '@domain/(.*)': '<rootDir>/src/domain/$1',
    '@application/(.*)': '<rootDir>/src/application/$1',
    '@infrastructure/(.*)': '<rootDir>/src/infrastructure/$1',
    '@main/(.*)': '<rootDir>/src/main/$1',
    '@test/(.*)': '<rootDir>/src/test/$1',
  },

  // A preset that is used as a base for Jest's configuration
  preset: '@shelf/jest-postgres',

  // A list of paths to directories that Jest should use to search for files in
  roots: ['<rootDir>/test'],

  // A map from regular expressions to paths to transformers
  transform: {
    ...tsjPreset.transform,
  },
};

module.exports = config;

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions