Skip to content

Commit

Permalink
Added more tests for documentation generation
Browse files Browse the repository at this point in the history
  • Loading branch information
dlmr committed Aug 31, 2016
1 parent e769dd2 commit f4c99e5
Show file tree
Hide file tree
Showing 51 changed files with 141 additions and 33 deletions.
2 changes: 2 additions & 0 deletions src/documentation/generateTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ export default function generateTable(initalDocumentationObject, header, setting

if (description) {
rows.push(description, '');
} else {
rows.push('');
}

if (raw) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import initContext from '../../../../src/context/initContext';
import initContext from '../../../src/context/initContext';

export default (projectPath, commands) => initContext({
commands,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
All commands can be called with some additional options as can be seen below.

### General options

| Name | Description | Required |
| --------------------- | ------------------------------------------------------------------------------------------------------------- | -------- |
| -b, --better-feedback | Will enable source-map-support and loud-rejection for a better experience with better feedback. | No |
Expand Down Expand Up @@ -49,12 +50,14 @@ __version__
Versions should match a tag on the Github repo and will default to master if none exists. When giving an input on the command line Roc will automatically add `v` in front of versions that starts with a number to match Github default that have versions tags that start with `v` like `v1.0.0`. `master` is also always available as an option.

#### Arguments

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| template | The template to use. Matches Github structure with Username/Repo or a local zip file. | | `Filepath` | No | No |
| version | The version to use. | | `String` | No | No |

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| -f, --force | Ignore non empty directory warning. | | `Boolean` | No | |
Expand All @@ -72,13 +75,15 @@ roc create new <name> [template] [version]
Alias for "init" that always will try to create a new directory.

#### Arguments

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| name | Name for a new directory to create the project in. | | `String` | Yes | No |
| template | The template to use. Matches Github structure with Username/Repo or a local zip file. | | `Filepath` | No | No |
| version | The version to use. | | `String` | No | No |

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| -f, --force | Ignore non empty directory warning. | | `Boolean` | No | |
Expand All @@ -104,6 +109,7 @@ roc meta docs
```

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ---------- | ------------------------------------------------------------- | -------------- | ----------------------------------------------------------------- | -------- | ------------ |
| --html | If HTML should be generated. (Not supported yet) | `false` | `Boolean` | No | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __Initial value:__ _Nothing_
__Expected return value:__ `{}`

#### Arguments

| Name | Description | Type | Required | Can be empty |
| ----------- | ---------------------------------------------------------------------------- | ---------- | -------- | ------------ |
| getSettings | A function that returns the settings after the context has been initialized. | `Function` | No | |
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Settings for `complex`

## Group

| Name | Description | Path | CLI option | Default | Type | Required | Can be empty | Extensions |
| ------ | ----------- | ------------ | -------------- | ------- | --------- | -------- | ------------ | --------------------------- |
| value2 | | group.value2 | --group-value2 | `false` | `Unknown` | No | Yes | roc-package-b, roc-plugin-b |
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
All commands can be called with some additional options as can be seen below.

### General options

| Name | Description | Required |
| --------------------- | ------------------------------------------------------------------------------------------------------------- | -------- |
| -b, --better-feedback | Will enable source-map-support and loud-rejection for a better experience with better feedback. | No |
Expand Down Expand Up @@ -49,12 +50,14 @@ __version__
Versions should match a tag on the Github repo and will default to master if none exists. When giving an input on the command line Roc will automatically add `v` in front of versions that starts with a number to match Github default that have versions tags that start with `v` like `v1.0.0`. `master` is also always available as an option.

#### Arguments

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| template | The template to use. Matches Github structure with Username/Repo or a local zip file. | | `Filepath` | No | No |
| version | The version to use. | | `String` | No | No |

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| -f, --force | Ignore non empty directory warning. | | `Boolean` | No | |
Expand All @@ -72,13 +75,15 @@ roc create new <name> [template] [version]
Alias for "init" that always will try to create a new directory.

#### Arguments

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| name | Name for a new directory to create the project in. | | `String` | Yes | No |
| template | The template to use. Matches Github structure with Username/Repo or a local zip file. | | `Filepath` | No | No |
| version | The version to use. | | `String` | No | No |

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ----------- | ------------------------------------------------------------------------------------- | ------- | ---------- | -------- | ------------ |
| -f, --force | Ignore non empty directory warning. | | `Boolean` | No | |
Expand All @@ -104,6 +109,7 @@ roc meta docs
```

#### Command options

| Name | Description | Default | Type | Required | Can be empty |
| ---------- | ------------------------------------------------------------- | -------------- | ----------------------------------------------------------------- | -------- | ------------ |
| --html | If HTML should be generated. (Not supported yet) | `false` | `Boolean` | No | |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ __Initial value:__ _Nothing_
__Expected return value:__ `{}`

#### Arguments

| Name | Description | Type | Required | Can be empty |
| ----------- | ---------------------------------------------------------------------------- | ---------- | -------- | ------------ |
| getSettings | A function that returns the settings after the context has been initialized. | `Function` | No | |
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Settings for `empty`

## Group

| Name | Description | Path | CLI option | Default | Type | Required | Can be empty | Extensions |
| ------ | ----------- | ------------ | -------------- | ------- | --------- | -------- | ------------ | --------------------------- |
| value2 | | group.value2 | --group-value2 | `false` | `Unknown` | No | Yes | roc-package-b, roc-plugin-b |
13 changes: 13 additions & 0 deletions test/documentation/helpers/addPadding.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import expect from 'expect';

import addPadding from '../../../src/documentation/helpers/addPadding';

describe('documentation', () => {
describe('helpers', () => {
describe('addPadding', () => {
it('should add correct spacing', () => {
expect(addPadding('Hello', 6)).toBe('Hello ');
});
});
});
});
24 changes: 24 additions & 0 deletions test/documentation/helpers/getDefaultValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import expect from 'expect';

import getDefaultValue from '../../../src/documentation/helpers/getDefaultValue';

describe('documentation', () => {
describe('helpers', () => {
describe('getDefaultValue', () => {
it('should return null for undefined', () => {
expect(getDefaultValue(undefined))
.toBe(undefined);
});

it('should return null as string', () => {
expect(getDefaultValue(null))
.toBe('null');
});

it('should return RegExp as string', () => {
expect(getDefaultValue(/abc/))
.toEqual('/abc/');
});
});
});
});
13 changes: 13 additions & 0 deletions test/documentation/helpers/pad.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import expect from 'expect';

import pad from '../../../src/documentation/helpers/pad';

describe('documentation', () => {
describe('helpers', () => {
describe('pad', () => {
it('should pad correctly', () => {
expect(pad(4, '-')).toBe('----');
});
});
});
});
13 changes: 13 additions & 0 deletions test/documentation/helpers/toCliOption.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import expect from 'expect';

import toCliOption from '../../../src/documentation/helpers/toCliOption';

describe('documentation', () => {
describe('helpers', () => {
describe('toCliOption', () => {
it('should return a option correct', () => {
expect(toCliOption(['build', 'option2'])).toBe('--build-option2');
});
});
});
});
7 changes: 3 additions & 4 deletions test/documentation/markdown/actionsToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { readFileSync } from 'fs';
import expect from 'expect';

import actionsToMarkdown from '../../../src/documentation/markdown/actionsToMarkdown';

import getContext from './fixtures/getContext';
import getContext from '../fixtures/getContext';

describe('documentation', () => {
describe('markdown', () => {
Expand All @@ -16,15 +15,15 @@ describe('documentation', () => {
});

it('should correctly format actions for project empty', () => {
const project = join(__dirname, 'fixtures', 'projects', 'empty');
const project = join(__dirname, '..', 'fixtures', 'projects', 'empty');
const context = getContext(project);

expect(actionsToMarkdown('empty', context.actions))
.toBe(readFileSync(join(project, 'docs', 'Actions.md'), 'utf8'));
});

it('should correctly format actions for project complex', () => {
const project = join(__dirname, 'fixtures', 'projects', 'complex');
const project = join(__dirname, '..', 'fixtures', 'projects', 'complex');
const context = getContext(project);

expect(actionsToMarkdown('complex', context.actions))
Expand Down
7 changes: 3 additions & 4 deletions test/documentation/markdown/commandsToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import expect from 'expect';

import commandsToMarkdown from '../../../src/documentation/markdown/commandsToMarkdown';
import defaultCommands from '../../../src/commands';

import getContext from './fixtures/getContext';
import getContext from '../fixtures/getContext';

describe('documentation', () => {
describe('markdown', () => {
Expand All @@ -17,15 +16,15 @@ describe('documentation', () => {
});

it('should correctly format commands for project empty', () => {
const project = join(__dirname, 'fixtures', 'projects', 'empty');
const project = join(__dirname, '..', 'fixtures', 'projects', 'empty');
const context = getContext(project, defaultCommands);

expect(commandsToMarkdown('empty', context.extensionConfig, context.commands, '/docs/Settings.md'))
.toEqual(readFileSync(join(project, 'docs', 'Commands.md'), 'utf8'));
});

it('should correctly format commands for project complex', () => {
const project = join(__dirname, 'fixtures', 'projects', 'complex');
const project = join(__dirname, '..', 'fixtures', 'projects', 'complex');
const context = getContext(project, defaultCommands);

expect(commandsToMarkdown('complex', context.extensionConfig, context.commands, '/docs/Settings.md'))
Expand Down
7 changes: 3 additions & 4 deletions test/documentation/markdown/configurationToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { readFileSync } from 'fs';
import expect from 'expect';

import configurationToMarkdown from '../../../src/documentation/markdown/configurationToMarkdown';

import getContext from './fixtures/getContext';
import getContext from '../fixtures/getContext';

describe('documentation', () => {
describe('markdown', () => {
Expand All @@ -17,15 +16,15 @@ describe('documentation', () => {
});

it('should correctly format config for project empty', () => {
const project = join(__dirname, 'fixtures', 'projects', 'empty');
const project = join(__dirname, '..', 'fixtures', 'projects', 'empty');
const context = getContext(project);

expect(configurationToMarkdown('empty', context.extensionConfig, context.meta))
.toBe(readFileSync(join(project, 'docs', 'Configuration.md'), 'utf8'));
});

it('should correctly format config for project complex', () => {
const project = join(__dirname, 'fixtures', 'projects', 'complex');
const project = join(__dirname, '..', 'fixtures', 'projects', 'complex');
const context = getContext(project);

expect(configurationToMarkdown('complex', context.extensionConfig, context.meta))
Expand Down
7 changes: 3 additions & 4 deletions test/documentation/markdown/createReadme.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ import expect from 'expect';

import settingsToMarkdown from '../../../src/documentation/markdown/settingsToMarkdown';
import defaultCommands from '../../../src/commands';

import getContext from './fixtures/getContext';
import getContext from '../fixtures/getContext';

describe('documentation', () => {
describe('markdown', () => {
Expand All @@ -17,15 +16,15 @@ describe('documentation', () => {
});

it('should correctly format settings for project empty', () => {
const project = join(__dirname, 'fixtures', 'projects', 'empty');
const project = join(__dirname, '..', 'fixtures', 'projects', 'empty');
const context = getContext(project, defaultCommands);

expect(settingsToMarkdown('empty', context.extensionConfig, context.meta))
.toEqual(readFileSync(join(project, 'docs', 'Settings.md'), 'utf8'));
});

it('should correctly format settings for project complex', () => {
const project = join(__dirname, 'fixtures', 'projects', 'complex');
const project = join(__dirname, '..', 'fixtures', 'projects', 'complex');
const context = getContext(project, defaultCommands);

expect(settingsToMarkdown('complex', context.extensionConfig, context.meta))
Expand Down
7 changes: 3 additions & 4 deletions test/documentation/markdown/dependenciesToMarkdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import { readFileSync } from 'fs';
import expect from 'expect';

import dependenciesToMarkdown from '../../../src/documentation/markdown/dependenciesToMarkdown';

import getContext from './fixtures/getContext';
import getContext from '../fixtures/getContext';

describe('documentation', () => {
describe('markdown', () => {
Expand All @@ -16,15 +15,15 @@ describe('documentation', () => {
});

it('should correctly format dependencies for project empty', () => {
const project = join(__dirname, 'fixtures', 'projects', 'empty');
const project = join(__dirname, '..', 'fixtures', 'projects', 'empty');
const context = getContext(project);

expect(dependenciesToMarkdown('empty', true, context.dependencies))
.toEqual(readFileSync(join(project, 'docs', 'Dependencies.md'), 'utf8'));
});

it('should correctly format dependencies for project complex', () => {
const project = join(__dirname, 'fixtures', 'projects', 'complex');
const project = join(__dirname, '..', 'fixtures', 'projects', 'complex');
const context = getContext(project);

expect(dependenciesToMarkdown('complex', true, context.dependencies))
Expand Down
Loading

0 comments on commit f4c99e5

Please sign in to comment.