Skip to content

Commit

Permalink
Edit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
yuanqing committed Aug 15, 2023
1 parent 9a084e9 commit 6b73b43
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
11 changes: 2 additions & 9 deletions packages/create-figma-plugin/src/create-figma-plugin-async.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import { basename, join } from 'node:path'
import { basename } from 'node:path'

import { constants, log } from '@create-figma-plugin/common'
import { green } from 'kleur/colors'
import { paramCase } from 'param-case'
import { pathExists } from 'path-exists'

import { copyTemplateAsync } from './utilities/copy-template-async.js'
import { createName } from './utilities/create-name.js'
Expand All @@ -18,12 +17,6 @@ export async function createFigmaPluginAsync(options: {
template?: string
}): Promise<void> {
try {
if (typeof options.name !== 'undefined') {
const directoryPath = join(process.cwd(), options.name)
if ((await pathExists(directoryPath)) === true) {
throw new Error(`Directory already exists: ./${options.name}`)
}
}
const templateName = await resolveTemplateNameAsync(options.template)
const templateType =
templateName.indexOf('plugin/') === 0 ? 'plugin' : 'widget'
Expand Down Expand Up @@ -52,7 +45,7 @@ export async function createFigmaPluginAsync(options: {
log.success('Done')
// eslint-disable-next-line no-console
console.log(`\nFirst:
${green(`cd ${directoryName}`)}
${green(`cd ${basename(directoryPath)}`)}
To build the ${templateType}:
${green('npm run build')}
Expand Down
33 changes: 27 additions & 6 deletions packages/create-figma-plugin/test/create-figma-plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import { createFigmaPluginAsync } from '../src/create-figma-plugin-async.js'

const __dirname = dirname(fileURLToPath(import.meta.url))

test('plugin template', async function (t) {
test('empty', async function (t) {
t.plan(9)
process.chdir(__dirname)
await cleanUpAsync()
process.chdir(join(__dirname, 'fixtures', '01-empty'))
await cleanUpAsync('figma-plugin')
t.false(await pathExists('figma-plugin'))
await createFigmaPluginAsync({
name: 'figma-plugin',
Expand All @@ -26,9 +26,30 @@ test('plugin template', async function (t) {
t.true(await pathExists('figma-plugin/README.md'))
t.true(await pathExists('figma-plugin/src'))
t.true(await pathExists('figma-plugin/src/main.ts'))
await cleanUpAsync()
await cleanUpAsync('figma-plugin')
})

async function cleanUpAsync(): Promise<void> {
await rimraf(join(process.cwd(), 'figma-plugin'))
test('directory-exists', async function (t) {
t.plan(10)
process.chdir(join(__dirname, 'fixtures', '02-directory-exists'))
await cleanUpAsync('figma-plugin-2')
t.false(await pathExists('figma-plugin-2'))
await createFigmaPluginAsync({
name: 'figma-plugin',
template: 'plugin/hello-world'
})
t.true(await pathExists('figma-plugin'))
t.true(await pathExists('figma-plugin-2'))
t.true(await pathExists('figma-plugin-2/.gitignore'))
t.true(await pathExists('figma-plugin-2/.vscode'))
t.true(await pathExists('figma-plugin-2/node_modules'))
t.true(await pathExists('figma-plugin-2/package.json'))
t.true(await pathExists('figma-plugin-2/README.md'))
t.true(await pathExists('figma-plugin-2/src'))
t.true(await pathExists('figma-plugin-2/src/main.ts'))
await cleanUpAsync('figma-plugin-2')
})

async function cleanUpAsync(directoryName: string): Promise<void> {
await rimraf(join(process.cwd(), directoryName))
}
Empty file.
Empty file.

0 comments on commit 6b73b43

Please sign in to comment.