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

Jest #9081

Merged
merged 41 commits into from
Sep 17, 2022
Merged

Jest #9081

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
3647c61
wip
syuilo Aug 31, 2022
c0d2596
wip
syuilo Sep 1, 2022
6202313
wip
syuilo Sep 1, 2022
4c9fe8a
wip
syuilo Sep 1, 2022
001d2df
wip
syuilo Sep 2, 2022
a81f170
wip
syuilo Sep 2, 2022
7650be4
Update test.yml
syuilo Sep 2, 2022
8fffac3
Update test.yml
syuilo Sep 2, 2022
c5e7ac8
Merge branch 'develop' into jest
syuilo Sep 3, 2022
1fc84b0
wip
syuilo Sep 3, 2022
6424b4e
wip
syuilo Sep 3, 2022
a7f78ec
wip
syuilo Sep 3, 2022
74f2e76
Update endpoints.ts
syuilo Sep 3, 2022
e2ac015
各テストファイルを直列に
syuilo Sep 7, 2022
8029b47
Update api-visibility.ts
syuilo Sep 8, 2022
39cf3c7
wip
syuilo Sep 8, 2022
e58c7e9
Merge branch 'develop' into jest
syuilo Sep 8, 2022
457b214
Merge branch 'develop' into jest
syuilo Sep 10, 2022
a6db7f2
Merge branch 'develop' into jest
syuilo Sep 10, 2022
9534518
Merge branch 'develop' into jest
syuilo Sep 10, 2022
d4df71e
Dependency Injection (#9085)
syuilo Sep 16, 2022
c984db0
wip
syuilo Sep 16, 2022
feabe88
Update relay.ts
syuilo Sep 16, 2022
721a556
wip
syuilo Sep 16, 2022
68ee0c0
:v:
syuilo Sep 17, 2022
46bce28
:v:
syuilo Sep 17, 2022
c622ac6
Update chart.ts
syuilo Sep 17, 2022
fd398ec
Update AppModule.ts
syuilo Sep 17, 2022
640f4a2
:v:
syuilo Sep 17, 2022
93ec532
:sparkles:
syuilo Sep 17, 2022
3f66c2f
:custard:
syuilo Sep 17, 2022
bcae29c
a
syuilo Sep 17, 2022
e7f6868
:v:
syuilo Sep 17, 2022
56bdf47
:ok:
syuilo Sep 17, 2022
df3bb15
Update HashtagService.ts
syuilo Sep 17, 2022
fbbece6
Update HashtagService.ts
syuilo Sep 17, 2022
f24e54f
syuilo Sep 17, 2022
8f77515
Update follow.ts
syuilo Sep 17, 2022
059f76e
syuilo Sep 17, 2022
c2dba0d
Update create.ts
syuilo Sep 17, 2022
3cc4fe9
Update messages.ts
syuilo Sep 17, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
8 changes: 6 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
pull_request:

jobs:
mocha:
jest:
runs-on: ubuntu-latest

strategy:
Expand Down Expand Up @@ -49,7 +49,11 @@ jobs:
- name: Build
run: yarn build
- name: Test
run: yarn mocha
run: yarn jest-and-coverage
- name: Upload Coverage
uses: codecov/codecov-action@v3
with:
files: ./packages/backend/coverage/coverage-final.json

e2e:
runs-on: ubuntu-latest
Expand Down
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ npm run test

#### Run specify test
```
npx cross-env TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT="./test/tsconfig.json" npx mocha test/foo.ts --require ts-node/register
npm run jest -- foo.ts
```

### e2e tests
Expand Down
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@
"cy:open": "cypress open --browser --e2e --config-file=cypress.config.ts",
"cy:run": "cypress run",
"e2e": "start-server-and-test start:test http://localhost:61812 cy:run",
"mocha": "cd packages/backend && cross-env NODE_ENV=test TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" npx mocha",
"test": "npm run mocha",
"jest": "cd packages/backend && cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --detectOpenHandles --runInBand",
"jest-and-coverage": "cd packages/backend && cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --coverage --forceExit --detectOpenHandles --runInBand",
"test": "npm run jest",
"test-and-coverage": "npm run jest-and-coverage",
"format": "gulp format",
"clean": "node ./scripts/clean.js",
"clean-all": "node ./scripts/clean-all.js",
Expand Down
10 changes: 0 additions & 10 deletions packages/backend/.mocharc.json

This file was deleted.

14 changes: 14 additions & 0 deletions packages/backend/jest-resolver.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// https://github.com/facebook/jest/issues/12270#issuecomment-1194746382

const nativeModule = require('node:module');

function resolver(module, options) {
const { basedir, defaultResolver } = options;
try {
return defaultResolver(module, options);
} catch (error) {
return nativeModule.createRequire(basedir).resolve(module);
}
}

module.exports = resolver;
214 changes: 214 additions & 0 deletions packages/backend/jest.config.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,214 @@
/*
* For a detailed explanation regarding each configuration property and type check, visit:
* https://jestjs.io/docs/en/configuration.html
*/

module.exports = {
// All imported modules in your tests should be mocked automatically
// automock: false,

// Stop running tests after `n` failures
// bail: 0,

// The directory where Jest should store its cached dependency information
// cacheDirectory: "C:\\Users\\ai\\AppData\\Local\\Temp\\jest",

// Automatically clear mock calls and instances between every test
// clearMocks: false,

// Indicates whether the coverage information should be collected while executing the test
// collectCoverage: false,

// An array of glob patterns indicating a set of files for which coverage information should be collected
collectCoverageFrom: ['src/**/*.ts'],

// The directory where Jest should output its coverage files
coverageDirectory: "coverage",

// An array of regexp pattern strings used to skip coverage collection
// coveragePathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// Indicates which provider should be used to instrument code for coverage
coverageProvider: "v8",

// A list of reporter names that Jest uses when writing coverage reports
// coverageReporters: [
// "json",
// "text",
// "lcov",
// "clover"
// ],

// An object that configures minimum threshold enforcement for coverage results
// coverageThreshold: undefined,

// A path to a custom dependency extractor
// dependencyExtractor: undefined,

// Make calling deprecated APIs throw helpful error messages
// errorOnDeprecated: false,

// Force coverage collection from ignored files using an array of glob patterns
// forceCoverageMatch: [],

// A path to a module which exports an async function that is triggered once before all test suites
// globalSetup: undefined,

// A path to a module which exports an async function that is triggered once after all test suites
// globalTeardown: undefined,

// A set of global variables that need to be available in all test environments
globals: {
"ts-jest": {
"useESM": true,
tsconfig: "test/tsconfig.json",
diagnostics: {
exclude: ['**'],
},
}
},

// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",

// An array of directory names to be searched recursively up from the requiring module's location
// moduleDirectories: [
// "node_modules"
// ],

// An array of file extensions your modules use
// moduleFileExtensions: [
// "js",
// "json",
// "jsx",
// "ts",
// "tsx",
// "node"
// ],

// A map from regular expressions to module names or to arrays of module names that allow to stub out resources with a single module
moduleNameMapper: {
"^@/(.*?).js": "<rootDir>/src/$1.ts",
'^(\\.{1,2}/.*)\\.js$': '$1',
},

// An array of regexp pattern strings, matched against all module paths before considered 'visible' to the module loader
// modulePathIgnorePatterns: [],

// Activates notifications for test results
// notify: false,

// An enum that specifies notification mode. Requires { notify: true }
// notifyMode: "failure-change",

// A preset that is used as a base for Jest's configuration
preset: "ts-jest/presets/js-with-ts-esm",

// Run tests from one or more projects
// projects: undefined,

// Use this configuration option to add custom reporters to Jest
// reporters: undefined,

// Automatically reset mock state between every test
// resetMocks: false,

// Reset the module registry before running each individual test
// resetModules: false,

// A path to a custom resolver
resolver: './jest-resolver.cjs',

// Automatically restore mock state between every test
// restoreMocks: false,

// The root directory that Jest should scan for tests and modules within
// rootDir: undefined,

// A list of paths to directories that Jest should use to search for files in
roots: [
"<rootDir>"
],

// Allows you to use a custom runner instead of Jest's default test runner
// runner: "jest-runner",

// The paths to modules that run some code to configure or set up the testing environment before each test
// setupFiles: [],

// A list of paths to modules that run some code to configure or set up the testing framework before each test
// setupFilesAfterEnv: [],

// The number of seconds after which a test is considered as slow and reported as such in the results.
// slowTestThreshold: 5,

// A list of paths to snapshot serializer modules Jest should use for snapshot testing
// snapshotSerializers: [],

// The test environment that will be used for testing
testEnvironment: "node",

// Options that will be passed to the testEnvironment
// testEnvironmentOptions: {},

// Adds a location field to test results
// testLocationInResults: false,

// The glob patterns Jest uses to detect test files
testMatch: [
"<rootDir>/test/unit/**/*.ts",
//"<rootDir>/test/e2e/**/*.ts"
],

// An array of regexp pattern strings that are matched against all test paths, matched tests are skipped
// testPathIgnorePatterns: [
// "\\\\node_modules\\\\"
// ],

// The regexp pattern or array of patterns that Jest uses to detect test files
// testRegex: [],

// This option allows the use of a custom results processor
// testResultsProcessor: undefined,

// This option allows use of a custom test runner
// testRunner: "jasmine2",

// This option sets the URL for the jsdom environment. It is reflected in properties such as location.href
// testURL: "http://localhost",

// Setting this value to "fake" allows the use of fake timers for functions such as "setTimeout"
// timers: "real",

// A map from regular expressions to paths to transformers
transform: {
"<regex_match_files>": [
"ts-jest",
{
"useESM": true
}
]
},

// An array of regexp pattern strings that are matched against all source file paths, matched files will skip transformation
// transformIgnorePatterns: [
// "\\\\node_modules\\\\",
// "\\.pnp\\.[^\\\\]+$"
// ],

// An array of regexp pattern strings that are matched against all modules before the module loader will automatically return a mock for them
// unmockedModulePathPatterns: undefined,

// Indicates whether each individual test should be reported during the run
// verbose: undefined,

// An array of regexp patterns that are matched against all source file paths before re-running tests in watch mode
// watchPathIgnorePatterns: [],

// Whether to use watchman for file crawling
// watchman: true,

extensionsToTreatAsEsm: ['.ts'],
};
6 changes: 4 additions & 2 deletions packages/backend/ormconfig.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DataSource } from 'typeorm';
import config from './built/config/index.js';
import { entities } from './built/db/postgre.js';
import { loadConfig } from './built/config.js';
import { entities } from './built/postgre.js';

const config = loadConfig();

export default new DataSource({
type: 'postgres',
Expand Down
17 changes: 12 additions & 5 deletions packages/backend/package.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{
"main": "./index.js",
"private": true,
"type": "module",
"scripts": {
"build": "tsc -p tsconfig.json || echo done. && tsc-alias -p tsconfig.json",
"watch": "node watch.mjs",
"lint": "eslint --quiet \"src/**/*.ts\"",
"mocha": "cross-env NODE_ENV=test TS_NODE_FILES=true TS_NODE_TRANSPILE_ONLY=true TS_NODE_PROJECT=\"./test/tsconfig.json\" mocha",
"test": "npm run mocha"
"jest": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --forceExit --detectOpenHandles --runInBand",
"jest-and-coverage": "cross-env NODE_ENV=test node --experimental-vm-modules --experimental-import-meta-resolve node_modules/jest/bin/jest.js --coverage --forceExit --detectOpenHandles --runInBand",
"test": "npm run jest",
"test-and-coverage": "npm run jest-and-coverage"
},
"resolutions": {
"chokidar": "^3.3.1",
Expand All @@ -23,9 +24,13 @@
"@koa/cors": "3.1.0",
"@koa/multer": "3.0.0",
"@koa/router": "9.0.1",
"@nestjs/common": "9.0.11",
"@nestjs/core": "9.0.11",
"@nestjs/testing": "9.0.11",
"@peertube/http-signature": "1.7.0",
"@sinonjs/fake-timers": "9.1.2",
"@syuilo/aiscript": "0.11.1",
"@types/pg": "8.6.5",
"ajv": "8.11.0",
"archiver": "5.3.1",
"autobind-decorator": "2.4.0",
Expand Down Expand Up @@ -71,7 +76,6 @@
"mfm-js": "0.23.0",
"mime-types": "2.1.35",
"misskey-js": "0.0.14",
"mocha": "10.0.0",
"ms": "3.0.0-canary.1",
"multer": "1.4.4",
"nested-property": "4.0.0",
Expand All @@ -96,6 +100,7 @@
"rename": "1.0.4",
"rndstr": "1.0.0",
"rss-parser": "3.12.0",
"rxjs": "7.5.6",
"s-age": "1.1.2",
"sanitize-html": "2.7.1",
"semver": "7.3.7",
Expand Down Expand Up @@ -129,6 +134,7 @@
"@types/cbor": "6.0.0",
"@types/escape-regexp": "0.0.1",
"@types/fluent-ffmpeg": "2.1.20",
"@types/jest": "29.0.0",
"@types/js-yaml": "4.0.5",
"@types/jsdom": "20.0.0",
"@types/jsonld": "1.5.6",
Expand All @@ -144,7 +150,6 @@
"@types/koa__cors": "3.1.1",
"@types/koa__multer": "2.0.4",
"@types/koa__router": "8.0.11",
"@types/mocha": "9.1.1",
"@types/node": "18.7.16",
"@types/node-fetch": "3.0.3",
"@types/nodemailer": "6.4.5",
Expand Down Expand Up @@ -173,6 +178,8 @@
"eslint": "8.23.0",
"eslint-plugin-import": "2.26.0",
"execa": "6.1.0",
"jest": "29.0.1",
"ts-jest": "28.0.8",
"typescript": "4.8.3"
}
}
15 changes: 15 additions & 0 deletions packages/backend/src/AppModule.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { Module } from '@nestjs/common';
import { CoreModule } from '@/core/CoreModule.js';
import { ServerModule } from '@/server/ServerModule.js';
import { GlobalModule } from '@/GlobalModule.js';
import { QueueProcessorModule } from '@/queue/QueueProcessorModule.js';

@Module({
imports: [
GlobalModule,
CoreModule,
ServerModule,
QueueProcessorModule,
],
})
export class AppModule {}
Loading