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