Skip to content

Conversation

kribblo
Copy link
Contributor

@kribblo kribblo commented Sep 29, 2016

Fixes path to http-proxy in two examples so that they can be run locally.

Copy link
Member

@indexzero indexzero left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 –– thanks!

@indexzero indexzero merged commit c662f9e into http-party:master Aug 22, 2019
This was referenced Mar 17, 2021
Copy link

@pashabhn pashabhn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const prompts = require('prompts');
const { findRepos } = require('jest-changed-files');
const simpleGit = require('simple-git/promise');

class JestWatchBranchPlugin {
getUsageInfo() {
return {
key: 'b',
prompt: 'test changes since a given branch',
};
}

async run(globalConfig, updateConfigAndRun) {
const branches = await this._getBranches(globalConfig.rootDir);
const { branch } = await prompts({
type: 'select',
name: 'branch',
message: 'Which branch do you want to base off of?',
choices: branches,
});

updateConfigAndRun({ mode: 'watch', changedSince: branch }); process.stdin.setRawMode(true); process.stdin.resume(); return true; 

}

async _getBranches(rootDir) {
// findRepos return a set of git repos and a set of hg repos.
// It doesn't really make sense to use this plugin across different
// repositories, so we assume there's a single repository
// for rootDir by just getting the first one
const { git: roots } = await findRepos([rootDir]);

const [root] = Array.from(roots); if (!root) { throw new Error('Unable to find git root'); } const repo = simpleGit(root); const { branches } = await repo.branch(); return Object.values(branches) .map(branch => ({ ...branch, name: branch.name.replace(/^remotes\//, ''), })) .map(({ current, name }) => ({ value: name, title: current ? `${name} (current branch)` : name, })); 

}
}

module.exports = JestWatchBranchPlugin;

@pashabhn
Copy link

pashabhn commented May 5, 2022

const prompts = require('prompts');
const { findRepos } = require('jest-changed-files');
const simpleGit = require('simple-git/promise');

class JestWatchBranchPlugin {
getUsageInfo() {
return {
key: 'b',
prompt: 'test changes since a given branch',
};
}

async run(globalConfig, updateConfigAndRun) {
const branches = await this._getBranches(globalConfig.rootDir);
const { branch } = await prompts({
type: 'select',
name: 'branch',
message: 'Which branch do you want to base off of?',
choices: branches,
});

updateConfigAndRun({ mode: 'watch', changedSince: branch }); process.stdin.setRawMode(true); process.stdin.resume(); return true; 

}

async _getBranches(rootDir) {
// findRepos return a set of git repos and a set of hg repos.
// It doesn't really make sense to use this plugin across different
// repositories, so we assume there's a single repository
// for rootDir by just getting the first one
const { git: roots } = await findRepos([rootDir]);

const [root] = Array.from(roots); if (!root) { throw new Error('Unable to find git root'); } const repo = simpleGit(root); const { branches } = await repo.branch(); return Object.values(branches) .map(branch => ({ ...branch, name: branch.name.replace(/^remotes\//, ''), })) .map(({ current, name }) => ({ value: name, title: current ? `${name} (current branch)` : name, })); 

}
}

module.exports = JestWatchBranchPlugin;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants