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

Unit testing with ES6 capabilities #1533

Closed
davidmarcoes opened this issue Jul 6, 2018 · 5 comments
Closed

Unit testing with ES6 capabilities #1533

davidmarcoes opened this issue Jul 6, 2018 · 5 comments
Assignees
Labels
issue: feature request Issue suggesting a new feature severity: medium If it breaks the basic use of the product but can be worked around

Comments

@davidmarcoes
Copy link

davidmarcoes commented Jul 6, 2018

What is the expected behavior?
Have a fully unit testing environment

After struggling for a while trying to make unit testing work, I finally end up with a configuration that works for me:

  1. Navigate to the root of a repo in which you want to implement unit testing (like strapi-admin)
  2. Create a .babelrc configuration file:
{
  "presets": [
    "env",
    "react"
  ],
  "plugins": [
    "transform-class-properties",
    "transform-object-rest-spread"
  ],
  "env": {
    "test": {
      "presets": [
        "env",
        "react"
        ],
      "plugins": [
        "transform-class-properties",
        "transform-object-rest-spread"
      ]
    }
  }
}
  1. Create a jest.config.js file:
module.exports = {
  name: 'setup',
  displayName: 'Setup',
  testMatch: [
    '<rootDir>/admin/src/**/?(*.)+(spec|test).js'
  ],
  testPathIgnorePatterns: [
    '<rootDir>/packages/',
  ],
  coveragePathIgnorePatterns: [
    '<rootDir>/dist/',
    '<rootDir>/node_modules/',
    '<rootDir>/out-tsc/',
    '<rootDir>/test/'
  ],
  transform: {
    '^.+\\.js?$': 'babel-jest'
  },
  transformIgnorePatterns: [
    '!node_modules/react-runtime',
    '!node_modules/strapi-helper-plugin/lib/src'
  ],
  moduleDirectories: [
    'admin/src',
    'node_modules',
    'node_modules/strapi-helper-plugin/lib/src',
    'node_modules/strapi-helper-plugin/node_modules'
  ],
  setupFiles: [
    'jest-localstorage-mock'
  ]
};
  1. Install some required dependencies:
    npm install --save-dev babel-jest jest-localstorage-mock

If you want to use additional dependencies, like Enzyme and so on, just include them in the previous sentence

  1. Modify the test script in package.json:
    "test": "jest --watch",

At this moment yo have a fully environment to develop and run your unit tests, with ES6 support and all the Strapi stuff working.

Would be very nice to have something similar to this fully integrated in the library and ready to use. IMHO unit testing is a must have.

@lauriejim lauriejim added issue: feature request Issue suggesting a new feature severity: medium If it breaks the basic use of the product but can be worked around labels Jul 9, 2018
@lauriejim
Copy link
Contributor

Thank you for this report.

@Aurelsicoko
Copy link
Member

@davidmarcoes It would be better to open a PR if it works on your side 👍

@lauriejim
Copy link
Contributor

@davidmarcoes check out the contributing guide to get started to submit a PR : https://github.com/strapi/strapi/blob/master/CONTRIBUTING.md

@davidmarcoes
Copy link
Author

@lauriejim I'm working on it, just facing some problems with babel when strapi-helper-tool is symlinked in a plugin.

I don't have to much free time at the moment, I'll try to send the PR ASAP.

@Aurelsicoko
Copy link
Member

Please refers to this card on Product Board (https://portal.productboard.com/strapi/c/26-new-plugin-architecture). I'm closing the issue because we will implement and write tests with the new plugin architecture.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
issue: feature request Issue suggesting a new feature severity: medium If it breaks the basic use of the product but can be worked around
Projects
None yet
Development

No branches or pull requests

3 participants