Skip to content

Commit

Permalink
feat: add blocks command to init new block (#330)
Browse files Browse the repository at this point in the history
* 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
justin-betty and archan937 authored Aug 22, 2022
1 parent 82823e7 commit 3b7aa94
Show file tree
Hide file tree
Showing 17 changed files with 25,028 additions and 56 deletions.
65 changes: 65 additions & 0 deletions __tests__/blocks/blockDefinitions.test.ts
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,
);
});
8 changes: 8 additions & 0 deletions __tests__/blocks/rootPackage.json
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"
}
}
2 changes: 1 addition & 1 deletion __tests__/functions/functionDefinition.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ test('stringifying function definitions', async (t: Context): Promise<void> => {
});

test('generating the package index.js', async (t: Context): Promise<void> => {
const expected = `import { default as sayHello_1_0 } from './say-hello/1.0';
const expected = `import { default as sayHello_1_0 } from './functions/say-hello/1.0';
const fn = {
"sayHello 1.0": sayHello_1_0,
Expand Down
Loading

0 comments on commit 3b7aa94

Please sign in to comment.