Skip to content

Commit

Permalink
chore: migrate faas test to new cli (#61)
Browse files Browse the repository at this point in the history
* chore: migrate faas test to new cli

* chore: update mjs

* chore: update mwts

* fix: cjs
  • Loading branch information
czy88840616 authored Sep 3, 2023
1 parent a2eae0a commit ab28fa4
Show file tree
Hide file tree
Showing 20 changed files with 63 additions and 53 deletions.
2 changes: 1 addition & 1 deletion v3/midway-component/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"@types/node": "^16.11.22",
"cross-env": "^6.0.0",
"jest": "^29.2.2",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
}
Expand Down
2 changes: 1 addition & 1 deletion v3/midway-framework-express/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"@types/node": "14",
"cross-env": "^6.0.0",
"jest": "^29.2.2",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
},
Expand Down
3 changes: 2 additions & 1 deletion v3/midway-framework-koa-esm/boilerplate/_.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extension": ["ts"],
"node-option": ["no-warnings", "loader=ts-node/esm"],
"spec": ["test/**/*.test.ts"]
"spec": ["test/**/*.test.ts"],
"require": ["test/setup.ts"]
}
2 changes: 1 addition & 1 deletion v3/midway-framework-koa-esm/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"scripts": {
"start": "cross-env NODE_ENV=production node ./bootstrap.js",
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/app",
"test": "cross-env NODE_ENV=unittest mocha --require test/setup.mjs",
"test": "cross-env NODE_ENV=unittest mocha",
"cov": "cross-env c8 --all --reporter=text --reporter=lcovonly npm run test",
"lint": "mwts check",
"lint:fix": "mwts fix",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHttpRequest } from '@midwayjs/mock';
import { Application } from '@midwayjs/koa';
import assert from 'assert';
import { getApp } from '../setup.mjs';
import { getApp } from '../setup.js';

describe('test/controller/home.test.ts', () => {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { createHttpRequest } from '@midwayjs/mock';
import { Application } from '@midwayjs/koa';
import assert from 'assert';
import { getApp } from '../setup.mjs';
import { getApp } from '../setup.js';

describe('test/controller/home.test.ts', () => {

Expand Down
2 changes: 1 addition & 1 deletion v3/midway-framework-koa/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@types/node": "14",
"cross-env": "^6.0.0",
"jest": "^29.2.2",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
},
Expand Down
2 changes: 1 addition & 1 deletion v3/midway-framework-web/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"@types/node": "14",
"cross-env": "^6.0.0",
"egg-mock": "^3.26.0",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"jest": "^29.2.2",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
Expand Down
2 changes: 1 addition & 1 deletion v3/midway-quick-start/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@types/node": "14",
"cross-env": "^6.0.0",
"jest": "^29.2.2",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
},
Expand Down
3 changes: 2 additions & 1 deletion v3/midway-serverless-http-new-esm/boilerplate/_.mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"extension": ["ts"],
"node-option": ["no-warnings", "loader=ts-node/esm"],
"spec": ["test/**/*.test.ts"]
"spec": ["test/**/*.test.ts"],
"require": ["test/setup.ts"]
}
4 changes: 2 additions & 2 deletions v3/midway-serverless-http-new-esm/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"scripts": {
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/function",
"test": "cross-env NODE_ENV=unittest mocha --require test/setup.mjs",
"test": "cross-env NODE_ENV=unittest mocha",
"cov": "cross-env c8 --all --reporter=text --reporter=lcovonly npm run test",
"deploy": "",
"lint": "mwts check",
Expand All @@ -32,7 +32,7 @@
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"mocha": "^10.2.0",
"mwts": "^1.0.5",
"mwts": "^1.3.0",
"mwtsc": "^1.0.0",
"ts-node": "^10.9.1",
"typescript": "~5.1.0"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createHttpRequest } from '@midwayjs/mock';
import { Application } from '@midwayjs/faas';
import { getApp } from './setup.mjs';
import { getApp } from './setup.js';
import assert from 'assert';

describe('test/index.test.ts', () => {
Expand Down
4 changes: 2 additions & 2 deletions v3/midway-serverless-http-new/boilerplate/_.eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"extends": "./node_modules/mwts/",
"ignorePatterns": ["node_modules", "dist", "test", "jest.config.js", "typings"],
"ignorePatterns": ["node_modules", "dist", "test", "typings"],
"env": {
"jest": true
"mocha": true
}
}
6 changes: 6 additions & 0 deletions v3/midway-serverless-http-new/boilerplate/_.mocharc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extension": ["ts"],
"node-option": ["no-warnings", "loader=ts-node/register"],
"spec": ["test/**/*.test.ts"],
"require": ["test/setup.ts"]
}
37 changes: 19 additions & 18 deletions v3/midway-serverless-http-new/boilerplate/_package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,30 +10,31 @@
"midway"
],
"scripts": {
"dev": "cross-env NODE_ENV=local midway-bin dev --ts",
"test": "cross-env midway-bin test --ts",
"build": "midway-bin build -c",
"dev": "cross-env NODE_ENV=local mwtsc --watch --run @midwayjs/mock/function",
"test": "cross-env NODE_ENV=unittest mocha",
"cov": "cross-env c8 --all --reporter=text --reporter=lcovonly npm run test",
"deploy": "",
"lint": "mwts check",
"lint:fix": "mwts fix"
"lint:fix": "mwts fix",
"ci": "npm run cov",
"build": "cross-env rm -rf dist && tsc"
},
"dependencies": {
"@midwayjs/core": "^3.0.0",
"@midwayjs/faas": "^3.0.0",
"@midwayjs/fc-starter": "^3.0.0",
"@midwayjs/core": "^3.12.0",
"@midwayjs/faas": "^3.12.0",
"@midwayjs/fc-starter": "^3.12.0",
"@midwayjs/logger": "^2.0.0"
},
"devDependencies": {
"@midwayjs/cli": "^2.0.0",
"@midwayjs/cli-plugin-faas": "^2.0.0",
"@midwayjs/fcli-plugin-fc": "^2.0.0",
"@midwayjs/mock": "^3.0.0",
"@types/jest": "^29.2.0",
"@types/node": "14",
"cross-env": "^6.0.0",
"jest": "^29.2.2",
"mwts": "^1.0.5",
"ts-jest": "^29.0.3",
"typescript": "~4.8.0"
"@midwayjs/mock": "^3.12.0",
"@types/mocha": "^10.0.1",
"@types/node": "16",
"c8": "^8.0.1",
"cross-env": "^7.0.3",
"mocha": "^10.2.0",
"mwts": "^1.3.0",
"mwtsc": "^1.0.0",
"ts-node": "^10.9.1",
"typescript": "~5.1.0"
}
}
6 changes: 0 additions & 6 deletions v3/midway-serverless-http-new/boilerplate/jest.config.js

This file was deleted.

20 changes: 6 additions & 14 deletions v3/midway-serverless-http-new/boilerplate/test/hello.test.ts
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
import { createFunctionApp, close, createHttpRequest } from '@midwayjs/mock';
import { Application, Framework } from '@midwayjs/faas';
import { createHttpRequest } from '@midwayjs/mock';
import { Application } from '@midwayjs/faas';
import { getApp } from './setup';
import * as assert from 'assert';

describe('test/index.test.ts', () => {

let app: Application;

beforeAll(async () => {
// create app
app = await createFunctionApp<Framework>();
});

afterAll(async () => {
await close(app);
});

it('should get result from http trigger', async () => {
const app: Application = getApp();
const result = await createHttpRequest(app).get('/').query({
name: 'Midway.js'
})
expect(result.text).toEqual('Hello Midway.js');
assert(result.text === 'Hello Midway.js');
});
});
15 changes: 15 additions & 0 deletions v3/midway-serverless-http-new/boilerplate/test/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { createFunctionApp, close } from '@midwayjs/mock';

let app;
export async function mochaGlobalSetup() {
// create app
app = await createFunctionApp();
}

export async function mochaGlobalTeardown() {
await close(app);
};

export function getApp() {
return app;
}

0 comments on commit ab28fa4

Please sign in to comment.