diff --git a/jest-preset.unit.js b/jest-preset.unit.js index 18da25e7f1..5a177bcf49 100644 --- a/jest-preset.unit.js +++ b/jest-preset.unit.js @@ -3,7 +3,7 @@ module.exports = { setupFilesAfterEnv: [__dirname + '/test/unit.setup.js'], modulePathIgnorePatterns: ['.cache', 'dist'], - testPathIgnorePatterns: ['.testdata.js', '.test.utils.js'], + testPathIgnorePatterns: ['.testdata.js', '.test.utils.[jt]s'], testMatch: ['/**/__tests__/**/*.[jt]s?(x)'], // Use `jest-watch-typeahead` version 0.6.5. Newest version 1.0.0 does not support jest@26 // Reference: https://github.com/jest-community/jest-watch-typeahead/releases/tag/v1.0.0 diff --git a/packages/core/strapi/lib/commands/__tests__/utils/data-transfer.test.utils.js b/packages/core/strapi/lib/commands/__tests__/commands.test.utils.js similarity index 100% rename from packages/core/strapi/lib/commands/__tests__/utils/data-transfer.test.utils.js rename to packages/core/strapi/lib/commands/__tests__/commands.test.utils.js diff --git a/packages/core/strapi/lib/commands/__tests__/admin.create-user.test.js b/packages/core/strapi/lib/commands/actions/admin/create-user/__tests__/admin.create-user.test.js similarity index 99% rename from packages/core/strapi/lib/commands/__tests__/admin.create-user.test.js rename to packages/core/strapi/lib/commands/actions/admin/create-user/__tests__/admin.create-user.test.js index 7e77945733..71d03d358c 100644 --- a/packages/core/strapi/lib/commands/__tests__/admin.create-user.test.js +++ b/packages/core/strapi/lib/commands/actions/admin/create-user/__tests__/admin.create-user.test.js @@ -24,7 +24,7 @@ const mock = { admin, }; -jest.mock('../../index', () => { +jest.mock('@strapi/strapi', () => { const impl = jest.fn(() => mock); impl.compile = jest.fn(); @@ -33,7 +33,7 @@ jest.mock('../../index', () => { }); const inquirer = require('inquirer'); -const createAdminCommand = require('../actions/admin/create-user/action'); +const createAdminCommand = require('../action'); describe('admin:create command', () => { beforeEach(() => { diff --git a/packages/core/strapi/lib/commands/__tests__/admin.reset-user-password.test.js b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.js similarity index 97% rename from packages/core/strapi/lib/commands/__tests__/admin.reset-user-password.test.js rename to packages/core/strapi/lib/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.js index 0ce97e3516..d4a0315243 100644 --- a/packages/core/strapi/lib/commands/__tests__/admin.reset-user-password.test.js +++ b/packages/core/strapi/lib/commands/actions/admin/reset-user-password/__tests__/admin.reset-user-password.test.js @@ -15,7 +15,7 @@ const mock = { admin, }; -jest.mock('../../index', () => { +jest.mock('@strapi/strapi', () => { const impl = jest.fn(() => mock); impl.compile = jest.fn(); @@ -24,7 +24,7 @@ jest.mock('../../index', () => { }); const inquirer = require('inquirer'); -const resetAdminPasswordCommand = require('../actions/admin/reset-user-password/action'); +const resetAdminPasswordCommand = require('../action'); describe('admin:reset-password command', () => { beforeEach(() => { diff --git a/packages/core/strapi/lib/commands/__tests__/export.test.js b/packages/core/strapi/lib/commands/actions/export/__tests__/export.test.js similarity index 96% rename from packages/core/strapi/lib/commands/__tests__/export.test.js rename to packages/core/strapi/lib/commands/actions/export/__tests__/export.test.js index e0cace9683..88c046a613 100644 --- a/packages/core/strapi/lib/commands/__tests__/export.test.js +++ b/packages/core/strapi/lib/commands/actions/export/__tests__/export.test.js @@ -1,6 +1,6 @@ 'use strict'; -const { expectExit } = require('./utils/data-transfer.test.utils'); +const { expectExit } = require('../../../__tests__/commands.test.utils'); describe('Export', () => { const defaultFileName = 'defaultFilename'; @@ -54,7 +54,7 @@ describe('Export', () => { jest.mock('@strapi/data-transfer', () => mockDataTransfer); - // mock utils + // command utils const mockUtils = { loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }), formatDiagnostic: jest.fn(), @@ -76,7 +76,7 @@ describe('Export', () => { exitMessageText: jest.fn(), }; jest.mock( - '../utils/data-transfer.js', + '../../../utils/data-transfer.js', () => { return mockUtils; }, @@ -90,7 +90,7 @@ describe('Export', () => { jest.spyOn(console, 'error').mockImplementation(() => {}); // Now that everything is mocked, load the 'export' command - const exportAction = require('../actions/export/action'); + const exportAction = require('../action'); beforeEach(() => { jest.clearAllMocks(); diff --git a/packages/core/strapi/lib/commands/__tests__/import.test.js b/packages/core/strapi/lib/commands/actions/import/__tests__/import.test.js similarity index 95% rename from packages/core/strapi/lib/commands/__tests__/import.test.js rename to packages/core/strapi/lib/commands/actions/import/__tests__/import.test.js index 6cce95dc49..d39783dd45 100644 --- a/packages/core/strapi/lib/commands/__tests__/import.test.js +++ b/packages/core/strapi/lib/commands/actions/import/__tests__/import.test.js @@ -7,7 +7,7 @@ const { engine: { DEFAULT_SCHEMA_STRATEGY, DEFAULT_VERSION_STRATEGY }, } = require('@strapi/data-transfer'); -const { expectExit } = require('./utils/data-transfer.test.utils'); +const { expectExit } = require('../../../__tests__/commands.test.utils'); const createTransferEngine = jest.fn(() => { return { @@ -62,7 +62,7 @@ describe('Import', () => { jest.mock('@strapi/data-transfer', () => mockDataTransfer); - // mock utils + // command utils const mockUtils = { loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }), formatDiagnostic: jest.fn(), @@ -82,7 +82,7 @@ describe('Import', () => { exitMessageText: jest.fn(), }; jest.mock( - '../utils/data-transfer.js', + '../../../utils/data-transfer.js', () => { return mockUtils; }, @@ -96,7 +96,7 @@ describe('Import', () => { jest.spyOn(console, 'error').mockImplementation(() => {}); // Now that everything is mocked, load the 'import' command - const importAction = require('../actions/import/action'); + const importAction = require('../action'); beforeEach(() => { jest.clearAllMocks(); diff --git a/packages/core/strapi/lib/commands/__tests__/templates.generate.js b/packages/core/strapi/lib/commands/actions/templates/generate/__tests__/templates.generate.js similarity index 98% rename from packages/core/strapi/lib/commands/__tests__/templates.generate.js rename to packages/core/strapi/lib/commands/actions/templates/generate/__tests__/templates.generate.js index 0bff56e30e..71ccc00dfe 100644 --- a/packages/core/strapi/lib/commands/__tests__/templates.generate.js +++ b/packages/core/strapi/lib/commands/actions/templates/generate/__tests__/templates.generate.js @@ -11,7 +11,7 @@ const { resolve, join } = require('path'); const fse = require('fs-extra'); const inquirer = require('inquirer'); -const exportTemplate = require('../actions/templates/generate/action'); +const exportTemplate = require('../action'); describe('templates:generate command', () => { beforeEach(() => { diff --git a/packages/core/strapi/lib/commands/__tests__/transfer.test.js b/packages/core/strapi/lib/commands/actions/transfer/__tests__/transfer.test.js similarity index 96% rename from packages/core/strapi/lib/commands/__tests__/transfer.test.js rename to packages/core/strapi/lib/commands/actions/transfer/__tests__/transfer.test.js index 9bf5f69b1d..c89b5db47e 100644 --- a/packages/core/strapi/lib/commands/__tests__/transfer.test.js +++ b/packages/core/strapi/lib/commands/actions/transfer/__tests__/transfer.test.js @@ -1,9 +1,9 @@ 'use strict'; -const { expectExit } = require('./utils/data-transfer.test.utils'); +const { expectExit } = require('../../../__tests__/commands.test.utils'); describe('Transfer', () => { - // mock utils + // command utils const mockUtils = { loadersFactory: jest.fn().mockReturnValue({ updateLoader: jest.fn() }), formatDiagnostic: jest.fn(), @@ -25,7 +25,7 @@ describe('Transfer', () => { exitMessageText: jest.fn(), }; jest.mock( - '../utils/data-transfer.js', + '../../../utils/data-transfer.js', () => { return mockUtils; }, @@ -72,7 +72,7 @@ describe('Transfer', () => { jest.mock('@strapi/data-transfer', () => mockDataTransfer); - const transferAction = require('../actions/transfer/action'); + const transferAction = require('../action'); // console spies jest.spyOn(console, 'log').mockImplementation(() => {});