Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[help]how to test the server code? #329

Closed
HaveF opened this issue Nov 20, 2016 · 3 comments
Closed

[help]how to test the server code? #329

HaveF opened this issue Nov 20, 2016 · 3 comments
Labels

Comments

@HaveF
Copy link
Contributor

HaveF commented Nov 20, 2016

Versions of kyt, node, OS

0.3.0

Bug or Feature?

Feature

Current Behavior

Don't know how to test the server code

This issue is come from kyt-starter-universal repo:

I just export src/server/index.jss app, and write a dead simple test file to test server.

But failed like this after run kyt test:

  ● Test suite failed to run

    ReferenceError: KYT is not defined

      at Object.<anonymous> (server/server.js:13:28)

caused by this line in source code kyt-starter-universal/index.js

const clientAssets = require(KYT.ASSETS_MANIFEST); // eslint-disable-line import/no-dynamic-require

This line is total fine when I run kyt dev, but failed at kyt test, I thought it must be kyt/test.js does not pass right env like kyt/dev.js does.

I also find KYT is defined in kyt/webpack.base.js, but do not know how to fix.

@delambo advice me to set package.json as below:

  "jest": {
    "globals": {
      "KYT": true
    }
  }

Console still complain: ReferenceError: KYT is not defined

Have any other idea I can try?

Thanks

@jaredmcdonald
Copy link
Contributor

jaredmcdonald commented Dec 9, 2016

hey @HaveF, sorry for the delayed response! try adding it to the modifyJestConfig callback in kyt.config.js

so, something like this:

modifyJestConfig(baseConfig) {
  return Object.assign(baseConfig, {
    globals: {
      KYT: {} // your KYT object mock goes here
    },
  })
}

@HaveF
Copy link
Contributor Author

HaveF commented Dec 10, 2016

@jaredmcdonald thanks for your response. It could fixed with your advice, and I modify kyt.config.js like this

  modifyJestConfig:    (baseConfig) => {
    return Object.assign(baseConfig, {
      globals: {
        KYT: {
          PUBLIC_DIR:      'src/public',
          ASSETS_MANIFEST: '--PATH---TO----PROJECT/build/publicAssets.json'
        } // your KYT object mock goes here
      },
    })
  }

But PUBLIC_DIR, and ASSETS_MANIFEST are default value of KYT, kyt/index.js at master · NYTimes/kyt

Maybe you can consider to add them as default JestConfig option.

Thanks!

@HaveF
Copy link
Contributor Author

HaveF commented Dec 10, 2016

#335

@HaveF HaveF closed this as completed Dec 10, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants