Skip to content

Commit

Permalink
f
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Jan 20, 2025
1 parent 13541fd commit 97cc4f0
Show file tree
Hide file tree
Showing 16 changed files with 90 additions and 132 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI lib/core
name: CI cluster1

on:
push:
Expand All @@ -13,6 +13,6 @@ jobs:
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20, 22'
test: 'npm run ci:lib/core'
test: 'npm run ci:cluster1'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI lib/other
name: CI cluster2

on:
push:
Expand All @@ -13,6 +13,6 @@ jobs:
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20, 22'
test: 'npm run ci:lib/other'
test: 'npm run ci:cluster2'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
18 changes: 0 additions & 18 deletions .github/workflows/nodejs-lib-cluster1.yml

This file was deleted.

18 changes: 0 additions & 18 deletions .github/workflows/nodejs-lib-cluster2.yml

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI lib/plugins
name: CI lib

on:
push:
Expand All @@ -13,6 +13,6 @@ jobs:
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20, 22'
test: 'npm run ci:lib/plugins'
test: 'npm run ci:lib'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 1 addition & 1 deletion .github/workflows/nodejs-other.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ jobs:
with:
os: 'ubuntu-latest, windows-latest'
version: '18, 20, 22'
test: 'npm run ci:lib/other'
test: 'npm run ci:other'
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
8 changes: 3 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,9 @@
"postci": "npm run prepublishOnly && npm run clean",
"prepublishOnly": "tshy && tshy-after && attw --pack --profile node16",
"ci:app": "npm run ci \"test/app/**/*.test.ts\"",
"ci:lib/cluster1": "npm run ci \"test/lib/cluster1/**/*.test.ts\"",
"ci:lib/cluster2": "npm run ci \"test/lib/cluster2/**/*.test.ts\"",
"ci:lib/core": "npm run ci \"test/lib/core/**/*.test.ts\"",
"ci:lib/plugins": "npm run ci \"test/lib/plugins/**/*.test.ts\"",
"ci:lib/other": "npm run ci \"test/lib/*.test.ts\"",
"ci:cluster1": "npm run ci \"test/cluster1/**/*.test.ts\"",
"ci:cluster2": "npm run ci \"test/cluster2/**/*.test.ts\"",
"ci:lib": "npm run ci \"test/lib/**/*.test.ts\"",
"ci:other": "npm run ci \"test/*.test.ts\"",
"site:dev": "cross-env APP_ROOT=./site dumi dev",
"site:build": "cross-env APP_ROOT=./site dumi build",
Expand Down
77 changes: 67 additions & 10 deletions test/agent.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,76 @@
import { strict as assert } from 'node:assert';
import fs from 'node:fs';
import path from 'node:path';
import { createApp, MockApplication, restore } from './utils.js';
import { mm } from '@eggjs/mock';
import { createApp, getFilepath, MockApplication, cluster } from './utils.js';

describe('test/agent.test.ts', () => {
afterEach(restore);
let app: MockApplication;
afterEach(mm.restore);

before(() => {
app = createApp('apps/agent-logger-config');
return app.ready();
describe('agent-logger-config', () => {
let app: MockApplication;

before(() => {
app = createApp('apps/agent-logger-config');
return app.ready();
});
after(() => app.close());

it('agent logger config should work', () => {
const fileTransport = app._agent.logger.get('file');
assert.equal(fileTransport.options.file, path.join('/tmp/foo', 'egg-agent.log'));
});
});
after(() => app.close());

it('agent logger config should work', () => {
const fileTransport = app._agent.logger.get('file');
assert.equal(fileTransport.options.file, path.join('/tmp/foo', 'egg-agent.log'));
describe('agent throw', () => {
const baseDir = getFilepath('apps/agent-throw');
let app: MockApplication;
before(() => {
app = cluster('apps/agent-throw');
return app.ready();
});
after(() => app.close());

it('should catch unhandled exception', done => {
app.httpRequest()
.get('/agent-throw-async')
.expect(200, err => {
assert(!err);
setTimeout(() => {
const body = fs.readFileSync(path.join(baseDir, 'logs/agent-throw/common-error.log'), 'utf8');
assert.match(body, /nodejs\.MessageUnhandledRejectionError: event: agent-throw-async, error: agent error in async function/);
app.notExpect('stderr', /nodejs.AgentWorkerDiedError/);
done();
}, 1000);
});
});

it('should exit on sync error throw', done => {
app.httpRequest()
.get('/agent-throw')
.expect(200, err => {
assert(!err);
setTimeout(() => {
const body = fs.readFileSync(path.join(baseDir, 'logs/agent-throw/common-error.log'), 'utf8');
assert.match(body, /nodejs\.MessageUnhandledRejectionError: event: agent-throw, error: agent error in sync function/);
app.notExpect('stderr', /nodejs.AgentWorkerDiedError/);
done();
}, 1000);
});
});

it('should catch uncaughtException string error', done => {
app.httpRequest()
.get('/agent-throw-string')
.expect(200, err => {
assert(!err);
setTimeout(() => {
const body = fs.readFileSync(path.join(baseDir, 'logs/agent-throw/common-error.log'), 'utf8');
assert.match(body, /nodejs\.MessageUnhandledRejectionError: event: agent-throw-string, error: agent error string/);
app.notExpect('stderr', /nodejs.AgentWorkerDiedError/);
done();
}, 1000);
});
});
});
});
6 changes: 3 additions & 3 deletions test/lib/application.test.ts → test/application.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ import fs from 'node:fs';
import path from 'node:path';
import { scheduler } from 'node:timers/promises';
import { pending } from 'pedding';
import { Application, CookieLimitExceedError } from '../../src/index.js';
import { MockApplication, cluster, createApp, getFilepath, startLocalServer } from '../utils.js';
import { Application, CookieLimitExceedError } from '../src/index.js';
import { MockApplication, cluster, createApp, getFilepath, startLocalServer } from './utils.js';

describe('test/lib/application.test.ts', () => {
describe('test/application.test.ts', () => {
let app: MockApplication;

afterEach(mm.restore);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { strict as assert } from 'node:assert';
import { scheduler } from 'node:timers/promises';
import { request } from '@eggjs/supertest';
import { ip } from 'address';
import { cluster, MockApplication } from '../../utils.js';
import { cluster, MockApplication } from '../utils.js';

const DEFAULT_BAD_REQUEST_HTML = `<html>
<head><title>400 Bad Request</title></head>
Expand All @@ -13,7 +13,7 @@ const DEFAULT_BAD_REQUEST_HTML = `<html>
</body>
</html>`;

describe('test/lib/cluster1/app_worker.test.ts', () => {
describe('test/cluster1/app_worker.test.ts', () => {
let app: MockApplication;
before(() => {
app = cluster('apps/app-server');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { readFile } from 'node:fs/promises';
import { strict as assert } from 'node:assert';
import { scheduler } from 'node:timers/promises';
import { MockApplication, createApp, getFilepath } from '../../utils.js';
import { MockApplication, createApp, getFilepath } from '../utils.js';

describe('test/lib/cluster1/cluster-client-error.test.ts', () => {
describe('test/cluster1/cluster-client-error.test.ts', () => {
let app: MockApplication;
before(async () => {
app = createApp('apps/cluster-client-error');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { strict as assert } from 'node:assert';
import { mm } from '@eggjs/mock';
import { MockApplication, createApp, singleProcessApp } from '../../utils.js';
import { MockApplication, createApp, singleProcessApp } from '../utils.js';

const innerClient = Symbol.for('ClusterClient#innerClient');

describe('test/lib/cluster1/cluster-client.test.ts', () => {
describe('test/cluster1/cluster-client.test.ts', () => {
let app: MockApplication;
describe('common mode', () => {
before(async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { scheduler } from 'node:timers/promises';
import { mm } from '@eggjs/mock';
import coffee, { Coffee } from 'coffee';
import { MockApplication, cluster, getFilepath } from '../../utils.js';
import { MockApplication, cluster, getFilepath } from '../utils.js';

describe('test/lib/cluster2/master.test.ts', () => {
describe('test/cluster2/master.test.ts', () => {
afterEach(mm.restore);

describe('app worker die', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/lib/egg.test.ts → test/egg.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import fs from 'node:fs';
import { scheduler } from 'node:timers/promises';
import { mm } from '@eggjs/mock';
import { Transport } from 'egg-logger';
import { createApp, cluster, getFilepath, MockApplication } from '../utils.js';
import { createApp, cluster, getFilepath, MockApplication } from './utils.js';
import assertFile from 'assert-file';
import { readJSONSync } from 'utility';

describe('test/lib/egg.test.ts', () => {
describe('test/egg.test.ts', () => {
afterEach(mm.restore);

describe('dumpConfig()', () => {
Expand Down
61 changes: 0 additions & 61 deletions test/lib/agent.test.ts

This file was deleted.

File renamed without changes.

0 comments on commit 97cc4f0

Please sign in to comment.