Skip to content

Commit

Permalink
test: restructure test dirs
Browse files Browse the repository at this point in the history
  • Loading branch information
innerdvations authored Apr 2, 2024
1 parent a0da7e7 commit cf82c83
Show file tree
Hide file tree
Showing 251 changed files with 50 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .github/filters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ backend:
- 'packages/**/strapi-server.js'
- 'packages/{utils,generators,cli,providers}/**'
- 'packages/core/*/{lib,bin,ee}/**'
- 'api-tests/**'
- 'tests/api/**'
frontend:
- '.github/actions/yarn-nm-install/*.yml'
- '.github/workflows/**'
Expand Down
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,8 @@ front-workspace.code-workspace
############################
playwright-report
test-results
!e2e/data/*.tar
e2e/.env
!tests/e2e/data/*.tar
tests/e2e/.env

############################
# Strapi
Expand Down
2 changes: 1 addition & 1 deletion jest-preset.unit.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

module.exports = {
setupFilesAfterEnv: [__dirname + '/test/setup/unit.setup.js'],
setupFilesAfterEnv: [__dirname + '/tests/setup/unit.setup.js'],
modulePathIgnorePatterns: ['.cache', 'dist'],
testPathIgnorePatterns: ['.testdata.js', '.test.utils.js', '.d.ts'],
testMatch: ['**/__tests__/**/*.{js,ts,jsx,tsx}'],
Expand Down
2 changes: 1 addition & 1 deletion jest.config.api.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module.exports = {
displayName: 'API integration tests',
testMatch: ['**/?(*.)+(spec|test).api.(js|ts)'],
testEnvironment: 'node',
setupFilesAfterEnv: ['<rootDir>/test/setup/jest-api.setup.js'],
setupFilesAfterEnv: ['<rootDir>/tests/setup/jest-api.setup.js'],
coveragePathIgnorePatterns: [
'<rootDir>/dist/',
'<rootDir>/node_modules/',
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,11 @@
"prettier:other": "prettier --cache --cache-strategy content \"**/*.{md,mdx,css,scss,yaml,yml}\"",
"prettier:write": "prettier --write \"**/*.{js,ts,jsx,tsx,json,md,mdx,css,scss,yaml,yml}\"",
"setup": "yarn && yarn clean && yarn build --skip-nx-cache",
"test:api": "node test/scripts/run-api-tests.js",
"test:api": "node tests/scripts/run-api-tests.js",
"test:clean": "rimraf ./coverage",
"test:e2e": "node test/scripts/run-e2e-tests.js",
"test:e2e:clean": "node test/scripts/run-e2e-tests.js clean",
"test:e2e:debug": "node test/scripts/run-e2e-tests.js --debug",
"test:e2e": "node tests/scripts/run-e2e-tests.js",
"test:e2e:clean": "node tests/scripts/run-e2e-tests.js clean",
"test:e2e:debug": "node tests/scripts/run-e2e-tests.js --debug",
"test:front": "cross-env IS_EE=true jest --config jest.config.front.js",
"test:front:all": "cross-env IS_EE=true nx run-many --target=test:front --nx-ignore-cycles",
"test:front:all:ce": "cross-env IS_EE=false nx run-many --target=test:front:ce --nx-ignore-cycles",
Expand All @@ -60,8 +60,8 @@
"test:front:update:ce": "yarn test:front:ce -u",
"test:front:watch": "cross-env IS_EE=true run test:front --watch",
"test:front:watch:ce": "cross-env IS_EE=false run test:front --watch",
"test:generate-app": "yarn build:ts && node test/scripts/generate-test-app.js",
"test:generate-app:no-build": "node test/scripts/generate-test-app.js",
"test:generate-app": "yarn build:ts && node tests/scripts/generate-test-app.js",
"test:generate-app:no-build": "node tests/scripts/generate-test-app.js",
"test:ts": "yarn test:ts:packages && yarn test:ts:front && yarn test:ts:back",
"test:ts:back": "nx run-many --target=test:ts:back --nx-ignore-cycles",
"test:ts:front": "nx run-many --target=test:ts:front --nx-ignore-cycles",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { errors } from '@strapi/utils';
import { omit } from 'lodash/fp';
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import constants from '../../services/constants';
import apiTokenController from '../api-token';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import contentApiController from '../content-api';

describe('Content API permissions', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import permissionController from '../permission';

describe('Permission Controller', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { errors } from '@strapi/utils';
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import roleController from '../role';

describe('Role controller', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { errors } from '@strapi/utils';
import { omit } from 'lodash/fp';
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../../tests/helpers/create-context';
import constants from '../../../services/constants';
import transferTokenController from '../../transfer/token';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { errors } from '@strapi/utils';
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import userController from '../user';

describe('User Controller', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable import/no-relative-packages */
// @ts-expect-error - test purposes
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import adminAuthStrategy from '../admin';

describe('Admin Auth Strategy', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/* eslint-disable import/no-relative-packages */
import { errors } from '@strapi/utils';
// @ts-expect-error - test purposes
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import apiTokenStrategy from '../api-token';

describe('API Token Auth Strategy', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import contentTypes from '../content-types';

describe('Content Types', () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import relations from '../relations';

const contentTypes = {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @ts-expect-error - types are not generated for this file
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../test/helpers/create-context';
import createContext from '../../../../../../../tests/helpers/create-context';
import singleTypes from '../single-types';
import populateBuilder from '../../services/populate-builder';

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import crypto from 'crypto';
// eslint-disable-next-line import/no-relative-packages
import createContext from '../../../../../../../tests/helpers/create-context';
import { generateAdminUserHash } from '../admin-user-hash';
import createContext from '../../../../../../../test/helpers/create-context';

describe('user email hash', () => {
test('should create a hash from admin user email', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import { omit } from 'lodash';
import { createStrapiInstance } from 'api-tests/strapi';
import { createAuthRequest } from 'api-tests/request';
import constants from '../../../packages/core/admin/server/src/services/constants';
import constants from '../../../../packages/core/admin/server/src/services/constants';

describe('Admin API Token v2 CRUD (api)', () => {
let rq;
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { omit } from 'lodash';
import { createStrapiInstance } from 'api-tests/strapi';
import { createAuthRequest } from 'api-tests/request';
import constants from '../../../packages/core/admin/server/src/services/constants';
import constants from '../../../../packages/core/admin/server/src/services/constants';

describe('Admin Transfer Token CRUD (api)', () => {
let rq;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { describeOnCondition } from 'api-tests/utils';
import {
WORKFLOW_MODEL_UID,
ENTITY_STAGE_ATTRIBUTE,
} from '../../../../packages/core/admin/ee/server/src/constants/workflows';
} from '../../../../../packages/core/admin/ee/server/src/constants/workflows';

const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import {
WORKFLOW_MODEL_UID,
ENTITY_STAGE_ATTRIBUTE,
ENTITY_ASSIGNEE_ATTRIBUTE,
} from '../../../../packages/core/admin/ee/server/src/constants/workflows';
} from '../../../../../packages/core/admin/ee/server/src/constants/workflows';

const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE';

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest } = require('api-tests/request');
const { createUtils } = require('api-tests/utils');

const { ALLOWED_SORT_STRINGS } = require('../../../../packages/core/upload/server/constants');
const { ALLOWED_SORT_STRINGS } = require('../../../../../packages/core/upload/server/constants');

const builder = createTestBuilder();
let strapi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ const fs = require('fs');
const path = require('path');
const _ = require('lodash/fp');

jest.mock('../../../../packages/core/upload/server/config', () => {
const config = jest.requireActual('../../../../packages/core/upload/server/config');
jest.mock('../../../../../packages/core/upload/server/config', () => {
const config = jest.requireActual('../../../../../packages/core/upload/server/config');
return _.set('default.sizeLimit', 1000, config); // 1kb
});

Expand Down
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 3 additions & 2 deletions e2e/scripts/dts-import.js → tests/e2e/scripts/dts-import.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { resolve } from 'path';
import { resolve, join } from 'path';
import { ALLOWED_CONTENT_TYPES, CUSTOM_TRANSFER_TOKEN_ACCESS_KEY } from '../constants';

const {
Expand All @@ -17,7 +17,8 @@ const {
* see: https://docs.strapi.io/developer-docs/latest/developer-resources/data-management.html
* @param {String} filePath the path to a DTS backup
*/
export const resetDatabaseAndImportDataFromPath = async (filePath) => {
export const resetDatabaseAndImportDataFromPath = async (file) => {
const filePath = join('./tests/e2e/data/', file);
const source = createSourceProvider(filePath);
const destination = createDestinationProvider();

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { login } from '../../utils/login';

test.describe('Login', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { login } from '../../utils/login';

test.describe('Log Out', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const fillValidSignUpForm = async ({ page }) => {

test.describe('Sign Up', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/without-admin.tar');
await resetDatabaseAndImportDataFromPath('without-admin.tar');
await page.goto('/admin');
await fillValidSignUpForm({ page });
});
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { test, expect } from '@playwright/test';
import { login } from '../../../utils/login';
import { resetDatabaseAndImportDataFromPath } from '../../../scripts/dts-import';
import { navToHeader, delay } from '../../../utils/shared';
import { navToHeader } from '../../../utils/shared';

const createTransferToken = async (page, tokenName, duration, type) => {
await navToHeader(
Expand All @@ -27,7 +27,7 @@ const createTransferToken = async (page, tokenName, duration, type) => {

test.describe('Transfer Tokens', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { findAndClose } from '../../utils/shared';

test.describe('Edit View', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { resetDatabaseAndImportDataFromPath } from '../../scripts/dts-import';

test.describe('List View', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const addEntryToRelease = async ({ page, releaseName }: { page: Page; releaseNam

describeOnCondition(edition === 'EE')('Release page', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE';

describeOnCondition(edition === 'EE')('Releases page', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { resetDatabaseAndImportDataFromPath } from '../../scripts/dts-import';

test.describe('Edit View CTB', () => {
test.beforeEach(async ({ page }) => {
await resetDatabaseAndImportDataFromPath('./e2e/data/with-admin.tar');
await resetDatabaseAndImportDataFromPath('with-admin.tar');
await page.goto('/admin');
await login({ page });
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/helpers/test-app.js → tests/helpers/test-app.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const path = require('path');
const fs = require('fs');
const rimraf = require('rimraf');
const execa = require('execa');
const generateNew = require('../../packages/generators/app/dist/generate-new');
const generateNew = require('@strapi/generate-new/dist/generate-new');

/**
* Deletes a test app
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ const { createConfig } = require('../../playwright.base.config');

const cwd = path.resolve(__dirname, '../..');
const testAppDirectory = path.join(cwd, 'test-apps', 'e2e');
const testRoot = path.join(cwd, 'e2e');
const testRoot = path.join(cwd, 'tests', 'e2e');
const testDomainRoot = path.join(testRoot, 'tests');
const templateDir = path.join(testRoot, 'app-template');

const pathExists = async (path) => {
Expand Down Expand Up @@ -67,7 +68,7 @@ yargs
command: '*',
description: 'run the E2E test suite',
builder: async (yarg) => {
const domains = await fs.readdir(path.join(cwd, 'e2e', 'tests'));
const domains = await fs.readdir(testDomainRoot);

yarg.option('concurrency', {
alias: 'c',
Expand Down Expand Up @@ -154,7 +155,7 @@ yargs
},
useNullAsDefault: true,
},
template: path.join(cwd, 'e2e', 'app-template'),
template: path.join(testRoot, 'app-template'),
link: true,
});

Expand Down Expand Up @@ -200,7 +201,7 @@ yargs
);

const config = createConfig({
testDir: path.join(cwd, 'e2e', 'tests', domain),
testDir: path.join(testDomainRoot, domain),
port,
appDir: testAppPath,
});
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit cf82c83

Please sign in to comment.