Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: add test cases #4

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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