Coder Social home page Coder Social logo

Breakage updating to 3.3.0 about jest-dynamodb HOT 5 CLOSED

shelfio avatar shelfio commented on September 25, 2024
Breakage updating to 3.3.0

from jest-dynamodb.

Comments (5)

harazdovskiy avatar harazdovskiy commented on September 25, 2024 1

@birtles Thanks for pointing out this issue, v3.3.1 was released with your fix!

from jest-dynamodb.

birtles avatar birtles commented on September 25, 2024 1

Thank you!

from jest-dynamodb.

vladholubiev avatar vladholubiev commented on September 25, 2024

@harazdovskiy could you please take a look? Likely a problem with export default vs export (just a guess)?

from jest-dynamodb.

birtles avatar birtles commented on September 25, 2024

Sorry again about the minimal bug report. I hope to have time to look into this tomorrow or the next day to provide more details.

from jest-dynamodb.

birtles avatar birtles commented on September 25, 2024

I think this comes down to:

const preset = require('./lib');

needing to specify .default before re-exporting the result.

My working

For the validation warnings, the stack I get is:

    at logValidationWarning (/home/birtles/project/node_modules/jest-validate/build/utils.js:101:11)
    at Object.unknownOptionWarning [as unknown] (/home/birtles/project/node_modules/jest-validate/build/warnings.js:44:35)
    at _validate (/home/birtles/project/node_modules/jest-validate/build/validate.js:81:17)
    at validate (/home/birtles/project/node_modules/jest-validate/build/validate.js:118:41)
    at normalize (/home/birtles/project/node_modules/@jest/core/node_modules/jest-config/build/normalize.js:645:65)
    at readConfig (/home/birtles/project/node_modules/@jest/core/node_modules/jest-config/build/index.js:219:74)
    at async readConfigs (/home/birtles/project/node_modules/@jest/core/node_modules/jest-config/build/index.js:404:26)
    at async runCLI (/home/birtles/project/node_modules/@jest/core/build/cli/index.js:140:59)
    at async Object.run (/home/birtles/project/node_modules/jest-cli/build/cli/index.js:155:37)

The options passed in to normalize are:

{
  transform: { '^.+\\.tsx?$': 'ts-jest' },
  default: {
    globalSetup: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/setup.js',
    globalTeardown: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/teardown.js',
    testEnvironment: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/environment.js'
  },
  testMatch: [ '**/*.test.ts' ],
  modulePathIgnorePatterns: [ '.aws-sam', 'cdk.out' ],
  moduleNameMapper: {
    '@birchill/bugsnag-zero/lambda-context': '@birchill/bugsnag-zero/lambda-context-cjs'
  },
  rootDir: '/home/birtles/project'
}

Digging into readConfig we are hitting this branch withconfigPath being /home/birtles/project/jest.config.js, and rawOptions being the above object.

That's coming from calling requireOrImportModule here:

https://github.com/facebook/jest/blob/main/packages/jest-config/src/readConfigFileAndSetRootDir.ts#L40

The requires the config file here:

https://github.com/facebook/jest/blob/main/packages/jest-util/src/requireOrImportModule.ts#L22

applyInteropRequireDefault is true so it ends up wrapping the object in { default: <config> } before accessing the default property anyway. No problem here.

The problem is why the config file has the globalSetup etc. members nested under default.

Looking at my config file I have:

const tsPreset = require('ts-jest/jest-preset');
const dynamodbPreset = require('@shelf/jest-dynamodb/jest-preset');

module.exports = {
  ...tsPreset,
  ...dynamodbPreset,
  testMatch: ['**/*.test.ts'],
  transform: {
    '^.+\\.tsx?$': 'ts-jest',
  },
  modulePathIgnorePatterns: ['.aws-sam', 'cdk.out'],
};

Here tsPreset is:

{ transform: { '^.+\\.tsx?$': 'ts-jest' } }

while dynamodbPreset is:

dynamodbPreset {
  default: {
    globalSetup: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/setup.js',
    globalTeardown: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/teardown.js',
    testEnvironment: '/home/birtles/project/node_modules/@shelf/jest-dynamodb/lib/environment.js'
  }
}

In jest-preset.js where we have:

const preset = require('./lib');

module.exports = preset;

preset is being resolved to:

{
  default: {
    globalSetup: '/home/birtles/10ten-server/node_modules/@shelf/jest-dynamodb/lib/setup.js',
    globalTeardown: '/home/birtles/10ten-server/node_modules/@shelf/jest-dynamodb/lib/teardown.js',
    testEnvironment: '/home/birtles/10ten-server/node_modules/@shelf/jest-dynamodb/lib/environment.js'
  }
}

I'm way out of my depth when it comes to module loading but just going off the explanation here on this SO answer and digging into lib/index.js, I wonder if we want to be doing:

const preset = require('./lib').default;

instead?

That seems to line up with this SO answer too.

If so, that would make b073618 the culprit.

Just changing:

const preset = require('./lib');

to:

const preset = require('./lib').default;

locally fixes it for me.

from jest-dynamodb.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.