Skip to content

Commit

Permalink
feat(dependencies): bumped to the alpha of the github scaffolder
Browse files Browse the repository at this point in the history
to get the initial support for github repo creation

for travi/github-scaffolder#1
  • Loading branch information
travi committed Jun 4, 2020
1 parent 7d663dc commit c0bfe33
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 8 deletions.
1 change: 1 addition & 0 deletions test/integration/features/other.feature
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Feature: Other Project Type

Scenario: simple
Given the project should be versioned in git
And the GitHub token is valid
And the project language should be Other
When the project is scaffolded
Then core ignores are defined
33 changes: 25 additions & 8 deletions test/integration/features/step_definitions/common-steps.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
import {readFile} from 'mz/fs';
import {readdir, readFile} from 'mz/fs';
import {resolve} from 'path';
import {Before, After, When, setWorldConstructor} from 'cucumber';
import {After, Before, setWorldConstructor, When} from 'cucumber';

import stubbedFs from 'mock-fs';
import {World} from '../support/world';
import action from '../../../../src/action';
import {githubToken} from './vcs/github-api-steps';

const pathToNodeModules = [__dirname, '../../../../', 'node_modules/'];

setWorldConstructor(World);

function loadOctokitFiles(octokitFiles) {
return octokitFiles
.map(file => readFile(resolve(...pathToNodeModules, 'octokit-pagination-methods/lib/', file)));
}

function buildOctokitFileMap(octokitFiles) {
return (acc, fileContents, index) => ({
...acc,
[octokitFiles[index]]: fileContents
});
}

Before(async () => {
// work around for overly aggressive mock-fs, see:
// https://github.com/tschaub/mock-fs/issues/213#issuecomment-347002795
require('mock-stdin'); // eslint-disable-line import/no-extraneous-dependencies

const octokitFiles = await readdir(resolve(...pathToNodeModules, 'octokit-pagination-methods/lib/'));
stubbedFs({
[`${process.env.HOME}/.netrc`]: `machine github.com\n login ${githubToken}`,
node_modules: {
'octokit-pagination-methods': {
lib: (await Promise.all(loadOctokitFiles(octokitFiles))).reduce(buildOctokitFileMap(octokitFiles), {})
},
'@travi': {
'project-scaffolder': {
templates: {
'editorconfig.txt': await readFile(resolve(
__dirname,
'../../../../',
'node_modules/',
...pathToNodeModules,
'@travi/project-scaffolder/templates/editorconfig.txt'
)),
'README.mustache': await readFile(resolve(
__dirname,
'../../../../',
'node_modules/',
...pathToNodeModules,
'@travi/project-scaffolder/templates/README.mustache'
))
}
Expand Down
26 changes: 26 additions & 0 deletions test/integration/features/step_definitions/vcs/github-api-steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import {After, Before, Given} from 'cucumber';
import any from '@travi/any';
import nock from 'nock';
import {OK} from 'http-status-codes';

let githubScope;
export const githubToken = any.string();
const debug = require('debug')('test');

Before(async () => {
nock.disableNetConnect();

githubScope = nock('https://api.github.com/').log(debug);
});

After(() => {
nock.enableNetConnect();
nock.cleanAll();
});

Given('the GitHub token is valid', async function () {
githubScope
.matchHeader('Authorization', `token ${githubToken}`)
.post('/user/repos')
.reply(OK);
});

0 comments on commit c0bfe33

Please sign in to comment.