-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27853b3
commit d934170
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
packages/tests/src/tools/src/commands/create-plugin/index.test.ts
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,80 @@ | ||
// Unless explicitly stated otherwise all files in this repository are licensed under the MIT License. | ||
// This product includes software developed at Datadog (https://www.datadoghq.com/). | ||
// Copyright 2019-Present Datadog, Inc. | ||
|
||
import commands from '@dd/tools/commands/create-plugin/index'; | ||
import { ROOT } from '@dd/tools/constants'; | ||
import { Cli } from 'clipanion'; | ||
import fs from 'fs'; | ||
import { vol } from 'memfs'; | ||
import path from 'path'; | ||
|
||
jest.mock('fs', () => require('memfs').fs); | ||
|
||
const getMirroredFixtures = (paths: string[], cwd: string) => { | ||
const fsa = jest.requireActual('fs'); | ||
const fixtures: Record<string, string> = {}; | ||
for (const p of paths) { | ||
fixtures[p] = fsa.readFileSync(path.resolve(cwd, p), 'utf-8'); | ||
} | ||
return fixtures; | ||
}; | ||
|
||
const getArgs = (opts: { | ||
name?: string; | ||
description?: string; | ||
codeowners?: string[]; | ||
type?: string; | ||
hooks?: string[]; | ||
}) => { | ||
const args: string[] = []; | ||
if (opts.name) { | ||
args.push('--name', opts.name); | ||
} | ||
if (opts.description) { | ||
args.push('--description', opts.description); | ||
} | ||
if (opts.codeowners) { | ||
args.push(...opts.codeowners.map((co) => ['--codeowner', co]).flat()); | ||
} | ||
if (opts.type) { | ||
args.push('--type', opts.type); | ||
} | ||
if (opts.hooks) { | ||
args.push(...opts.hooks.map((h) => ['--hook', h]).flat()); | ||
} | ||
return args; | ||
}; | ||
|
||
describe('Command create-plugin', () => { | ||
const fixtures = getMirroredFixtures( | ||
['.github/CODEOWNERS', `packages/plugins/telemetry/package.json`], | ||
ROOT, | ||
); | ||
console.log('FIXTURES', Object.keys(fixtures)); | ||
beforeEach(() => { | ||
// Mock the files that are touched by yarn cli create-plugin and yarn cli integrity. | ||
vol.fromJSON(fixtures, ROOT); | ||
}); | ||
|
||
afterEach(() => { | ||
vol.reset(); | ||
}); | ||
|
||
test('It should create a plugin.', async () => { | ||
const cli = new Cli(); | ||
cli.register(commands[0]); | ||
|
||
const args = getArgs({ | ||
name: 'Testing #1', | ||
description: 'Testing plugin', | ||
codeowners: ['@codeowners'], | ||
type: 'universal', | ||
hooks: ['enforce'], | ||
}); | ||
const result = await cli.run(['create-plugin', ...args]); | ||
console.log('TEST', fs.readdirSync(ROOT)); | ||
console.log(result); | ||
// console.log(Object.keys(vol.toJSON()).map((k) => k.replace(ROOT, '.'))); | ||
}); | ||
}); |
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