Skip to content

Commit

Permalink
Merge pull request #4 from dream-num/test/add-test
Browse files Browse the repository at this point in the history
test: add test cases
  • Loading branch information
jikkai authored Jan 3, 2024
2 parents a3a9519 + 8d688e6 commit 65b007d
Show file tree
Hide file tree
Showing 8 changed files with 1,986 additions and 33 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@ Thumbs.db
.env.development.local
.env.test.local
.env.production.local

# Test
coverage
42 changes: 42 additions & 0 deletions __tests__/create.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import fs from 'fs-extra'
import { createProject } from '../src/create'
import { traverseDirectory } from '../src/utils/convert'

jest.mock('fs-extra')
jest.mock('../src/utils/convert')

describe('createProject', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('should copy files from source directory to destination directory', () => {
// Arrange
const fromDir = '/path/to/source'
const toDir = '/path/to/destination'
const projectName = 'myProject'

// Act
createProject(fromDir, toDir, projectName)

// Assert
expect(fs.copySync).toHaveBeenCalledWith(fromDir, toDir, { overwrite: true })
})

it('should call traverseDirectory with the correct arguments', () => {
// Arrange
const fromDir = '/path/to/source'
const toDir = '/path/to/destination'
const projectName = 'myProject'

// Act
createProject(fromDir, toDir, projectName)

// Assert
expect(traverseDirectory).toHaveBeenCalledWith(toDir, {
GITIGNORE: '.gitignore',
PROJECT_NAME: projectName,
PROJECT_UPPER_NAME: 'MyProject'
})
})
})
2 changes: 1 addition & 1 deletion esbuild.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const config = {
entryPoints: {
index: './src/main.ts'
},
format: 'esm',
format: 'cjs',
outdir: './dist'
}

Expand Down
9 changes: 9 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { JestConfigWithTsJest } from 'ts-jest'

export default {
preset: 'ts-jest',
testEnvironment: 'node',
testPathIgnorePatterns: ['/node_modules/', '/templates/'],
collectCoverageFrom: ['<rootDir>/src/**/*.ts'],
coveragePathIgnorePatterns: ['/node_modules/', '/templates/'],
} as JestConfigWithTsJest
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
{
"name": "@univerjs/create-cli",
"version": "0.3.1",
"description": "",
"description": "Command-line tool for quickly creating univer plugins.",
"main": "index.js",
"type": "module",
"author": "DreamNum <[email protected]>",
"license": "MIT",
"publishConfig": {
Expand All @@ -15,6 +14,8 @@
"scripts": {
"dev": "node ./esbuild.config.mjs --watch",
"build": "node ./esbuild.config.mjs",
"test": "jest",
"coverage": "jest --coverage",
"release": "npm run build && release-it"
},
"dependencies": {
Expand All @@ -27,10 +28,14 @@
"devDependencies": {
"@types/ejs": "^3.1.5",
"@types/fs-extra": "^11.0.4",
"@types/jest": "^29.5.11",
"esbuild": "^0.19.11",
"esbuild-plugin-clean": "^1.0.1",
"jest": "^29.7.0",
"minimist": "^1.2.8",
"release-it": "^17.0.1",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.2",
"typescript": "^5.3.3"
}
}
Loading

0 comments on commit 65b007d

Please sign in to comment.