-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add blocks command to init new block (#330)
* feat: add blocks command to init new block * feat: add publish functionality * feat: add tests * fix: throw error when function is not found * feat: add publish functions * fix: feedback * feat: validate functions before publishing * feat: finish publishing functions blocks * fix: remove unused code Co-authored-by: Paul Engel <[email protected]>
- Loading branch information
1 parent
82823e7
commit 3b7aa94
Showing
17 changed files
with
25,028 additions
and
56 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,65 @@ | ||
import fs from 'fs-extra'; | ||
import test, { ExecutionContext } from 'ava'; | ||
import path from 'path'; | ||
import { | ||
blockDefinitionPath, | ||
blockDefinitions, | ||
createPackageJson, | ||
newBlockDefinition, | ||
} from '../../src/blocks/blockDefinitions'; | ||
|
||
type Context = ExecutionContext<unknown>; | ||
|
||
console.log(process.cwd()); | ||
|
||
const supportDir = path.join(process.cwd(), '__tests__/support/blocks/'); | ||
|
||
test.afterEach(() => { | ||
fs.emptyDirSync(supportDir); | ||
}); | ||
|
||
test('blockDefinitionPath', async (t: Context): Promise<void> => { | ||
t.is(blockDefinitionPath('/blocks', 'test'), '/blocks/test.json'); | ||
}); | ||
|
||
test('creating a new blockDefinition', async (t: Context): Promise<void> => { | ||
const blockName = `block${Math.random().toString()}`; | ||
|
||
t.is( | ||
newBlockDefinition(supportDir, blockName), | ||
`blocks/${blockName}.json created`, | ||
); | ||
}); | ||
|
||
test('returns 2 blocks', async (t: Context): Promise<void> => { | ||
fs.emptyDirSync(supportDir); | ||
const newBlocks = ['test', 'block']; | ||
|
||
newBlocks.map((block) => newBlockDefinition(supportDir, block)); | ||
|
||
const blocks = blockDefinitions(supportDir); | ||
const numberOfBlocks = blocks.length; | ||
|
||
t.assert(numberOfBlocks === 2); | ||
}); | ||
|
||
test('creating a package.json', async (t: Context): Promise<void> => { | ||
const packageJson = JSON.stringify( | ||
{ | ||
name: 'test', | ||
version: '1.0.0', | ||
private: 'true', | ||
dependencies: { | ||
lodash: '^4.17.21', | ||
}, | ||
}, | ||
null, | ||
2, | ||
); | ||
|
||
t.assert( | ||
createPackageJson('test', '__tests__/blocks/rootPackage.json', [ | ||
'lodash', | ||
]) === packageJson, | ||
); | ||
}); |
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,8 @@ | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"private": "true", | ||
"dependencies": { | ||
"lodash": "^4.17.21" | ||
} | ||
} |
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
Oops, something went wrong.