Git Product home page Git Product logo

strapi-unit-test-example's Introduction

strapi-unit-test-example's People

Contributors

dependabot[bot] avatar gustawdaniel avatar kazdan1994 avatar mfelix5 avatar qunabu avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

strapi-unit-test-example's Issues

Jest fails on strapi versions >=4.0.8

Hello, thank you for this functioning example of Strapi V4 + Jest !

I'm trying to run this with Typescript as well, and I ran into a ton of weird errors.
While debugging, I tried removing all .ts and TS-related stuff from my own project to try and recreate this one and see if I could get it to work without TS (then gradually add stuff back to see where the problem comes from).

I realized that my @strapi/strapi (and related libraries) is a higher version than this one.

This project uses version 4.0.7 and works.
Updating to higher versions (even just version 4.0.8) fails for me.
I'd like to get it to work with version 4.3.5 ideally.

I don't know if this will also fix the errors I'm getting with typescript but it would be a good start, and I could at the very least run Strapi V4 + Jest without Typescript (and maybe add typescript back later).

Has anyone tried running this on higher @strapi/strapi versions and gotten it to work ?

SQLLite Error and strapi.store is not a function

Hi,

So, I've been trying to get unit tests for v4 running using this example and there seems be be some issue with the code for me. When I copy it exactly as is I get the following error

create table public.strapi_migrations (id integer not null primary key autoincrement, name varchar(255), time datetime) - SQLITE_ERROR: unknown database public (ignore the weird formatting)

which implies that Strapi().load() is not populating the test.db properly. When I change Strapi().load() to Strapi() it seems to remedy this issue, or at least get rid of the error, but I can't be sure it's actually populating the table correctly because then I get an unrelated error TypeError: strapi.store is not a function for the createUser function in factory.js. When I log Strapi while running the tests the object doesn't seem to have the .store property. Any idea what's going on here?

Some useful context might be that I'm running Strapi 4.2.2, because I can't update to the latest version due to an issue with building the admin panel in the latest version that hasn't been resolved

Can't run tests

I was hoping that this would help me get tests working with v4 but I'm getting the same errors that I've seen with other attempts. Perhaps you can help? Below is from a run in a fresh docker container with Node v14.19.0. Any help to getting worknig tests would be appreciated.

yarn run v1.22.17
$ jest --runInBand --coverage=true

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at getUserPluginsConfig (node_modules/@strapi/strapi/lib/core/loaders/plugins/get-user-plugins-config.js:31:28)
      at getEnabledPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/get-enabled-plugins.js:80:29)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:82:26)
 FAIL  tests/user/user.e2e.test.js (34.443 s)
  ● Console

    console.log
      
         ╭──────────────────────────────────────────────────────────────────────────────╮
         │                                                                              │
         │              A new version of Strapi is available 4.0.7 → 4.1.3              │
         │   Check out the new releases at: https://github.com/strapi/strapi/releases   │
         │                                                                              │
         ╰──────────────────────────────────────────────────────────────────────────────╯
      

      at display (node_modules/@strapi/strapi/lib/utils/update-notifier/index.js:83:13)

  ● Confirmation User e2e test › should register, send email with confirmation link, link should confirm account

    thrown: "Exceeded timeout of 5000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      13 |
      14 | /** this code is called once before any test is called */
    > 15 | beforeAll(async () => {
         | ^
      16 |   await setupStrapi(); // singleton so it can be called many times
      17 | });
      18 |

      at Object.<anonymous> (tests/user/user.e2e.test.js:15:1)

  ● Confirmation User e2e test › should register, send email with confirmation link, link should confirm account

    TypeError: strapi.store is not a function

      100 |   environment = ""
      101 | ) => {
    > 102 |   const pluginStore = strapi.store({
          |                              ^
      103 |     environment: environment,
      104 |     type: "plugin",
      105 |     name: pluginName,

      at updatePluginStore (tests/helpers/strapi.js:102:30)
      at tests/user/user.e2e.test.js:28:11


  ● Test suite failed to run

    TypeError: strapi.store is not a function

      100 |   environment = ""
      101 | ) => {
    > 102 |   const pluginStore = strapi.store({
          |                              ^
      103 |     environment: environment,
      104 |     type: "plugin",
      105 |     name: pluginName,

      at updatePluginStore (tests/helpers/strapi.js:102:30)
      at tests/user/user.e2e.test.js:43:11


ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 3)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 4)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 2)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:96:26)
      at Strapi.loadPlugins (node_modules/@strapi/strapi/lib/Strapi.js:277:5)
          at async Promise.all (index 1)
 FAIL  tests/user/user.test.js (9.06 s)
  ● Default User methods › should login user and return jwt token

    thrown: "Exceeded timeout of 5000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      14 |
      15 | /** this code is called once before any test is called */
    > 16 | beforeAll(async () => {
         | ^
      17 |   await setupStrapi(); // singleton so it can be called many times
      18 | });
      19 |

      at Object.<anonymous> (tests/user/user.test.js:16:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

  ● Default User methods › should login user and return jwt token

    TypeError: strapi.store is not a function

      30 | const createUser = async (data) => {
      31 |   /** Gets the default user role */
    > 32 |   const pluginStore = await strapi.store({
         |                                    ^
      33 |     type: "plugin",
      34 |     name: "users-permissions",
      35 |   });

      at createUser (tests/user/factory.js:32:36)
      at tests/user/user.test.js:29:18
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

  ● Default User methods › should return users data for authenticated user

    thrown: "Exceeded timeout of 5000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      14 |
      15 | /** this code is called once before any test is called */
    > 16 | beforeAll(async () => {
         | ^
      17 |   await setupStrapi(); // singleton so it can be called many times
      18 | });
      19 |

      at Object.<anonymous> (tests/user/user.test.js:16:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

  ● Default User methods › should return users data for authenticated user

    TypeError: strapi.store is not a function

      30 | const createUser = async (data) => {
      31 |   /** Gets the default user role */
    > 32 |   const pluginStore = await strapi.store({
         |                                    ^
      33 |     type: "plugin",
      34 |     name: "users-permissions",
      35 |   });

      at createUser (tests/user/factory.js:32:36)
      at tests/user/user.test.js:29:18
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

  ● Default User methods › should allow register users 

    thrown: "Exceeded timeout of 5000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      14 |
      15 | /** this code is called once before any test is called */
    > 16 | beforeAll(async () => {
         | ^
      17 |   await setupStrapi(); // singleton so it can be called many times
      18 | });
      19 |

      at Object.<anonymous> (tests/user/user.test.js:16:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

  ● Default User methods › should allow register users 

    TypeError: strapi.store is not a function

      30 | const createUser = async (data) => {
      31 |   /** Gets the default user role */
    > 32 |   const pluginStore = await strapi.store({
         |                                    ^
      33 |     type: "plugin",
      34 |     name: "users-permissions",
      35 |   });

      at createUser (tests/user/factory.js:32:36)
      at tests/user/user.test.js:29:18
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

  ● Confirmation User methods › unconfirmed user should not login

    thrown: "Exceeded timeout of 5000 ms for a hook.
    Use jest.setTimeout(newTimeout) to increase the timeout value, if this is a long-running test."

      14 |
      15 | /** this code is called once before any test is called */
    > 16 | beforeAll(async () => {
         | ^
      17 |   await setupStrapi(); // singleton so it can be called many times
      18 | });
      19 |

      at Object.<anonymous> (tests/user/user.test.js:16:1)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:320:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:173:3)

  ● Confirmation User methods › unconfirmed user should not login

    TypeError: strapi.store is not a function

      100 |   environment = ""
      101 | ) => {
    > 102 |   const pluginStore = strapi.store({
          |                              ^
      103 |     environment: environment,
      104 |     type: "plugin",
      105 |     name: pluginName,

      at updatePluginStore (tests/helpers/strapi.js:102:30)
      at tests/user/user.test.js:98:11
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)


  ● Test suite failed to run

    TypeError: strapi.store is not a function

      100 |   environment = ""
      101 | ) => {
    > 102 |   const pluginStore = strapi.store({
          |                              ^
      103 |     environment: environment,
      104 |     type: "plugin",
      105 |     name: pluginName,

      at updatePluginStore (tests/helpers/strapi.js:102:30)
      at tests/user/user.test.js:108:11
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:333:13)
      at runJest (node_modules/@jest/core/build/runJest.js:404:19)

Running coverage on untested files...
ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 2)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 4)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 3)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at loadJsFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:9:22)
      at loadFile (node_modules/@strapi/strapi/lib/core/app-configuration/load-config-file.js:35:14)
      at getUserPluginsConfig (node_modules/@strapi/strapi/lib/core/loaders/plugins/get-user-plugins-config.js:31:28)
      at applyUserConfig (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:59:29)
      at Object.loadPlugins (node_modules/@strapi/strapi/lib/core/loaders/plugins/index.js:101:3)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 3)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 4)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at loadFile (node_modules/@strapi/strapi/lib/core/loaders/apis.js:153:14)
      at loadDir (node_modules/@strapi/strapi/lib/core/loaders/apis.js:142:38)
          at async Promise.all (index 2)
      at loadAPI (node_modules/@strapi/strapi/lib/core/loaders/apis.js:76:7)
      at Object.<anonymous>.module.exports [as loadAPIs] (node_modules/@strapi/strapi/lib/core/loaders/apis.js:30:19)
------------------------|---------|----------|---------|---------|-------------------
File                    | % Stmts | % Branch | % Funcs | % Lines | Uncovered Line #s 
------------------------|---------|----------|---------|---------|-------------------
All files               |      50 |      100 |     100 |      50 |                   
 category/controllers   |     100 |      100 |     100 |     100 |                   
  category.js           |     100 |      100 |     100 |     100 |                   
 category/routes        |     100 |      100 |     100 |     100 |                   
  category.js           |     100 |      100 |     100 |     100 |                   
 category/services      |     100 |      100 |     100 |     100 |                   
  category.js           |     100 |      100 |     100 |     100 |                   
 restaurant/controllers |       0 |      100 |     100 |       0 |                   
  restaurant.js         |       0 |      100 |     100 |       0 | 7-9               
 restaurant/routes      |       0 |      100 |     100 |       0 |                   
  restaurant.js         |       0 |      100 |     100 |       0 | 7-9               
 restaurant/services    |       0 |      100 |     100 |       0 |                   
  restaurant.js         |       0 |      100 |     100 |       0 | 7-9               
------------------------|---------|----------|---------|---------|-------------------
Test Suites: 2 failed, 2 total
Tests:       5 failed, 5 total
Snapshots:   0 total
Time:        44.943 s
Ran all test suites.

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.e2e.test.js.

      at getDialectClass (node_modules/@strapi/database/lib/dialects/index.js:10:14)
      at getDialect (node_modules/@strapi/database/lib/dialects/index.js:19:23)
      at new Database (node_modules/@strapi/database/lib/index.js:38:20)
      at Function.Object.<anonymous>.Database.init (node_modules/@strapi/database/lib/index.js:84:33)
      at Strapi.bootstrap (node_modules/@strapi/strapi/lib/Strapi.js:345:30)

ReferenceError: You are trying to `import` a file after the Jest environment has been torn down. From tests/user/user.test.js.

      at getDialectClass (node_modules/@strapi/database/lib/dialects/index.js:10:14)
      at getDialect (node_modules/@strapi/database/lib/dialects/index.js:19:23)
      at new Database (node_modules/@strapi/database/lib/index.js:38:20)
      at Function.Object.<anonymous>.Database.init (node_modules/@strapi/database/lib/index.js:84:33)
      at Strapi.bootstrap (node_modules/@strapi/strapi/lib/Strapi.js:345:30)
Jest did not exit one second after the test run has completed.

This usually means that there are asynchronous operations that weren't stopped in your tests. Consider running Jest with `--detectOpenHandles` to troubleshoot this issue.
^C
node ➜ /workspaces/strapi-unit-test-example (main ✗) $ node -v
v14.19.0

Licence

Please add a license, such that other users may use and contribute to this repo

Strapi not loading for tests in pipeline

Hi there, using this general pattern for unit tests has worked for me so far. I can run unit tests as expected locally using npm run test. However, trying to run the same command in a bitbucket pipeline, I end up with an error:

console.error
Unhandled error
at process.uncaught (node_modules/jest-jasmine2/build/jasmine/Env.js:248:21)

I believe this is because Strapi is not loading successfully here:

await Strapi().load();

I note that I get the same error locally if I comment out the Jest timeout:

jest.setTimeout(30000);

Here are the contents of my bitbuckets-pipeline.yml file:

image: node:12.18.4

definitions:
step: &build
name: test and build
caches:
- node
script:
- apt-get update && apt-get install -y zip unzip
- npm install
- npm run test
- npm run build
- zip application.zip . -r * .[^.]*
artifacts:
- application.zip
pipelines:
default:
- step: *build
branches:
master:
- step: *build
- step:
name: Deploy master to Production env
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "us-east-2"
APPLICATION_NAME: "trapi-prod"
ENVIRONMENT_NAME: 'production'
ZIP_FILE: "application.zip"
dev:
- step: *build
- step:
name: Deploy dev to Development env
script:
- pipe: atlassian/aws-elasticbeanstalk-deploy:0.5.0
variables:
AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
AWS_DEFAULT_REGION: "us-east-2"
APPLICATION_NAME: "trapi-dev"
ENVIRONMENT_NAME: 'development'
ZIP_FILE: "application.zip"

Any insight is appreciated.

Thanks!

Test doesn't pass because Strapi timeout

Hi,

After pulling your repo, I try to run test and got these errors.

[2020-06-03T10:04:03.051Z] warn The bootstrap function is taking unusually long to execute (3500 miliseconds).
[2020-06-03T10:04:03.055Z] warn Make sure you call it?
[2020-06-03T10:04:05.791Z] debug POST /auth/local (1316 ms) 200
FAIL tests/app.test.js (11.972 s)
✕ strapi is defined (6 ms)
✕ should return hello world (5 ms)
✕ should login user and return jwt token (4221 ms)
✕ should return users data for authenticated user (220 ms)

● strapi is defined

Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.

  at mapper (node_modules/jest-jasmine2/build/queueRunner.js:29:45)

● should return hello world

Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.

  at mapper (node_modules/jest-jasmine2/build/queueRunner.js:29:45)

● should return hello world

TypeError: Cannot read property 'address' of undefined

  3 | it("should return hello world", async (done) => {
  4 |   await request(strapi.server) // app server is and instance of Class: http.Server
> 5 |     .get("/hello")
    |      ^
  6 |     .expect(200) // Expect response http code 200
  7 |     .then((data) => {
  8 |       expect(data.text).toBe("Hello World!"); // expect the response text

  at Test.serverAddress (node_modules/supertest/lib/test.js:55:18)
  at new Test (node_modules/supertest/lib/test.js:36:12)
  at Object.get (node_modules/supertest/index.js:25:14)
  at Object.<anonymous> (tests/hello/index.js:5:6)

● should login user and return jwt token

Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.

  at mapper (node_modules/jest-jasmine2/build/queueRunner.js:29:45)

● should return users data for authenticated user

Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.Error: Timeout - Async callback was not invoked within the 5000 ms timeout specified by jest.setTimeout.

  at mapper (node_modules/jest-jasmine2/build/queueRunner.js:29:45)

Test Suites: 1 failed, 1 total
Tests: 4 failed, 4 total
Snapshots: 0 total
Time: 12.078 s, estimated 14 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Can you answer if it's my fail or a problem with your repo. Thank you !

Strapi Unit Test Helpers as NPM Library

I just saw your talk on Strapi Conf and love the potential of your unit test helpers for our projects. Combined with Strapi's upcoming TS support, proper testing is what we're missing to build larger non-CMS backend projects with Strapi.

It's already great that we have this repo, thank you for that 🙏!

On top of that, it'd be great if you'd publish the helpers as an NPM library. That'd make setting up projects with proper unit tests much more pleasant, plus remove the maintenance burden of having to copy over files into the individual repos.

Missing await

There should be await before instance.destroy()

tests\helpers\strapi.js
line 40:
await instance.destroy();

When it's missing I receive error while trying to unlink db.

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.