mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-11 20:08:37 +00:00
test(server): migrate to node internal test (#2000)
This commit is contained in:
@@ -1,12 +1,13 @@
|
||||
{
|
||||
"name": "@affine/server",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"version": "0.5.3",
|
||||
"description": "Affine Node.js server",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "nodemon ./src/index.ts",
|
||||
"test": "ava"
|
||||
"test": "NODE_ENV=test node --loader ts-node/esm.mjs --es-module-specifier-resolution node --test ./src/tests/*",
|
||||
"test:coverage": "NODE_V8_COVERAGE=.coverage NODE_ENV=test node --loader ts-node/esm.mjs --es-module-specifier-resolution node --experimental-test-coverage ./src/tests/*"
|
||||
},
|
||||
"dependencies": {
|
||||
"@apollo/server": "^4.6.0",
|
||||
@@ -28,10 +29,10 @@
|
||||
"@nestjs/testing": "^9.4.0",
|
||||
"@types/lodash-es": "^4.14.194",
|
||||
"@types/node": "^18.15.11",
|
||||
"ava": "^5.2.0",
|
||||
"nodemon": "^2.0.22",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.0.4"
|
||||
"typescript": "^5.0.4",
|
||||
"vitest": "^0.30.1"
|
||||
},
|
||||
"nodemonConfig": {
|
||||
"exec": "node",
|
||||
@@ -54,26 +55,5 @@
|
||||
"DEBUG_COLORS": true
|
||||
},
|
||||
"delay": 1000
|
||||
},
|
||||
"ava": {
|
||||
"extensions": {
|
||||
"ts": "module"
|
||||
},
|
||||
"nodeArguments": [
|
||||
"--loader",
|
||||
"ts-node/esm.mjs",
|
||||
"--es-module-specifier-resolution",
|
||||
"node"
|
||||
],
|
||||
"files": [
|
||||
"src/**/*.spec.ts"
|
||||
],
|
||||
"require": [
|
||||
"./src/prelude.ts"
|
||||
],
|
||||
"environmentVariables": {
|
||||
"TS_NODE_PROJECT": "./tsconfig.json",
|
||||
"NODE_ENV": "test"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,4 +17,4 @@ const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||
bodyParser: true,
|
||||
});
|
||||
|
||||
await app.listen(process.env.PORT ?? 3000);
|
||||
await app.listen(process.env.PORT ?? 3010);
|
||||
|
||||
@@ -35,6 +35,15 @@ export class Workspace implements workspaces {
|
||||
export class WorkspaceResolver {
|
||||
constructor(private readonly prisma: PrismaService) {}
|
||||
|
||||
// debug only query should be removed
|
||||
@Query(() => [Workspace], {
|
||||
name: 'workspaces',
|
||||
description: 'Get all workspaces',
|
||||
})
|
||||
async workspaces() {
|
||||
return this.prisma.workspaces.findMany();
|
||||
}
|
||||
|
||||
@Query(() => Workspace, {
|
||||
name: 'workspace',
|
||||
description: 'Get workspace by id',
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
import { Test } from '@nestjs/testing';
|
||||
import test from 'ava';
|
||||
import { equal, ok } from 'node:assert';
|
||||
import { beforeEach, test } from 'node:test';
|
||||
|
||||
import { Config, ConfigModule } from '..';
|
||||
import { Test } from '@nestjs/testing';
|
||||
|
||||
import { Config, ConfigModule } from '../config';
|
||||
import { getDefaultAFFiNEConfig } from '../config/default';
|
||||
|
||||
globalThis.AFFiNE = getDefaultAFFiNEConfig();
|
||||
|
||||
let config: Config;
|
||||
test.beforeEach(async () => {
|
||||
beforeEach(async () => {
|
||||
const module = await Test.createTestingModule({
|
||||
imports: [ConfigModule.forRoot()],
|
||||
}).compile();
|
||||
@@ -12,8 +17,8 @@ test.beforeEach(async () => {
|
||||
});
|
||||
|
||||
test('should be able to get config', t => {
|
||||
t.assert(typeof config.host === 'string');
|
||||
t.is(config.env, 'test');
|
||||
ok(typeof config.host === 'string');
|
||||
equal(config.env, 'test');
|
||||
});
|
||||
|
||||
test('should be able to override config', async t => {
|
||||
@@ -26,5 +31,5 @@ test('should be able to override config', async t => {
|
||||
}).compile();
|
||||
const config = module.get(Config);
|
||||
|
||||
t.is(config.host, 'testing');
|
||||
ok(config.host, 'testing');
|
||||
});
|
||||
Reference in New Issue
Block a user