-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(io): add Jest tests for io package
- Loading branch information
Showing
12 changed files
with
213 additions
and
318 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libs/**/lib |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,5 +45,8 @@ | |
"prettier": "^2.2.1", | ||
"ts-node": "^10.9.2", | ||
"typescript": "^5.4.2" | ||
}, | ||
"dependencies": { | ||
"jest": "^29.7.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 在你的测试文件的顶部,模拟 @mincloudx/baas 包 | ||
// jest.mock('@mincloudx/baas', () => ({ | ||
// TableObject: jest.fn().mockImplementation(tableName => ({ | ||
// create: jest.fn(), | ||
// get: jest.fn(), | ||
// update: jest.fn(), | ||
// delete: jest.fn(), | ||
// })), | ||
// })); | ||
|
||
// 引入所需模块和初始化代码 | ||
require('../tool/baas-init'); | ||
const { createIo } = require('..'); | ||
const TABLE_OPERATION_KEYS = ['create', 'get', 'update', 'delete']; | ||
|
||
describe('createIo Functionality', () => { | ||
it('register table to io', async () => { | ||
const tables = ['channel', 'product']; | ||
const io = createIo({ tables }); | ||
|
||
expect(io).toHaveProperty('channel'); | ||
TABLE_OPERATION_KEYS.forEach(key => { | ||
expect(io.channel).toHaveProperty(key); | ||
}); | ||
}); | ||
|
||
it('io.channel should return an instance of BaaS.TableObject', () => { | ||
const tables = ['channel']; | ||
const io = createIo({ tables }); | ||
|
||
expect(io.channel).toBeDefined(); | ||
expect(io.channel.table).toBeDefined(); | ||
expect(io.channel.table._tableID).toEqual('channel'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
{ | ||
"extends": "../../tsconfig.json", | ||
"include": ["src", "test", "types", "tool/baas-init.ts"], | ||
"exclude": ["**/*.test.ts"], | ||
"compilerOptions": { | ||
"typeRoots": [ | ||
"../../node_modules/@types", | ||
"./node_modules/@types", | ||
"./types" | ||
], | ||
"allowJs": true, | ||
"noImplicitAny": false, | ||
"target": "ES2019", | ||
"module": "commonJS", | ||
"moduleResolution": "node", | ||
"lib": ["es2015", "dom"] | ||
}, | ||
"include": ["src", "test", "types"] | ||
"target": "es2022", | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"lib": ["es2015"], | ||
"declarationDir": "lib/types", | ||
"outDir": "lib", | ||
"rootDir": ".", | ||
"baseUrl": "./src" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,35 @@ | ||
// Generated using webpack-cli https://github.com/webpack/webpack-cli | ||
|
||
const path = require('path'); | ||
|
||
const isProduction = process.env.NODE_ENV == 'production'; | ||
|
||
const config = { | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
// 使 Node.js 与 browser 均能使用 | ||
libraryTarget: 'umd', | ||
globalObject: 'this', | ||
}, | ||
plugins: [ | ||
// Add your plugins here | ||
// Learn more about plugins from https://webpack.js.org/configuration/plugins/ | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(ts|tsx)$/i, | ||
loader: 'ts-loader', | ||
exclude: ['/node_modules/'], | ||
}, | ||
{ | ||
test: /\.(eot|svg|ttf|woff|woff2|png|jpg|gif)$/i, | ||
type: 'asset', | ||
}, | ||
|
||
// Add your rules for custom modules here | ||
// Learn more about loaders from https://webpack.js.org/loaders/ | ||
], | ||
}, | ||
resolve: { | ||
extensions: ['.tsx', '.ts', '.jsx', '.js', '...'], | ||
}, | ||
}; | ||
|
||
module.exports = () => { | ||
if (isProduction) { | ||
config.mode = 'production'; | ||
} else { | ||
config.mode = 'development'; | ||
} | ||
return config; | ||
return { | ||
mode: isProduction ? 'production' : 'development', | ||
entry: './src/index.ts', | ||
output: { | ||
path: path.resolve(__dirname, 'dist'), | ||
libraryTarget: 'umd', | ||
globalObject: 'this', | ||
}, | ||
plugins: [ | ||
// Add your plugins here | ||
// Learn more about plugins from https://webpack.js.org/configuration/plugins/ | ||
], | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.(ts|tsx)$/i, | ||
loader: 'ts-loader', | ||
exclude: ['/node_modules/'], | ||
}, | ||
], | ||
}, | ||
resolve: { | ||
alias: { | ||
'@': path.resolve(__dirname, './src'), | ||
}, | ||
extensions: ['.ts', '.js'], | ||
fallback: { path: false }, | ||
}, | ||
}; | ||
}; |
Oops, something went wrong.