Skip to content

Commit

Permalink
chore: apply eslint func-style rule
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed Aug 27, 2024
1 parent cf06b47 commit 05628f4
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 168 deletions.
2 changes: 1 addition & 1 deletion src/run-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ export class RunContextBase<GeneratorType extends BaseGenerator = DefaultGenerat
.catch(error => {
if (this.listenerCount('end') === 0 && this.listenerCount('error') === 0) {
// When there is no listeners throw a unhandled rejection.
setImmediate(async function () {
setImmediate(async () => {
throw error;
});
} else {
Expand Down
4 changes: 2 additions & 2 deletions src/run-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import { type AskedQuestions } from './adapter.js';

const isObject = object => typeof object === 'object' && object !== null && object !== undefined;

function convertArguments(arguments_) {
const convertArguments = arguments_ => {
if (arguments_.length > 1) {
return [[...arguments_]];
}

const [argument] = arguments_;
return Array.isArray(argument) ? argument : [argument];
}
};

/**
* Provides options for `RunResult`s.
Expand Down
16 changes: 8 additions & 8 deletions test/adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,27 @@ import assert from 'node:assert';
import { describe, expect, it } from 'esmocha';
import { TestAdapter } from '../src/adapter.js';

describe('TestAdapter', function () {
describe('#prompt()', function () {
it('allows pre-filled answers', async function () {
describe('TestAdapter', () => {
describe('#prompt()', () => {
it('allows pre-filled answers', async () => {
const adapter = new TestAdapter();
return adapter
.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }], {
respuesta: 'foo',
})
.then(function (answers) {
.then(answers => {
assert.equal(answers.respuesta, 'foo');
});
});
});
describe('#queue()', function () {
it('should execute the callback', async function () {
describe('#queue()', () => {
it('should execute the callback', async () => {
const adapter = new TestAdapter();
await expect(adapter.queue(() => 2)).resolves.toBe(2);
});
});
describe('#progress()', function () {
it('should execute the callback', async function () {
describe('#progress()', () => {
it('should execute the callback', async () => {
const adapter = new TestAdapter();
await expect(
adapter.progress(({ step }) => {
Expand Down
78 changes: 39 additions & 39 deletions test/helpers.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ const __dirname = dirname(fileURLToPath(import.meta.url));
const { resolve, join } = path;
const environment = await createEnvironment({ adapter: new TestAdapter() });

describe('yeoman-test', function () {
describe('yeoman-test', () => {
beforeEach(function () {
process.chdir(join(__dirname, './fixtures'));

this.StubGenerator = class extends Generator {};
});

describe('.createGenerator()', function () {
describe('.createGenerator()', () => {
it('create a new generator', async function () {
const generator = await helpers.createGenerator('unicorn:app', {
dependencies: [[this.StubGenerator, { namespace: 'unicorn:app' }]],
Expand Down Expand Up @@ -57,79 +57,79 @@ describe('yeoman-test', function () {
});
});

describe('.mockPrompt()', function () {
describe('.mockPrompt()', () => {
beforeEach(async function () {
this.generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });
helpers.mockPrompt(this.generator, { answer: 'foo' });
});

it('uses default values', function () {
return this.generator.prompt([{ name: 'respuesta', type: 'input', default: 'bar' }]).then(function (answers) {
return this.generator.prompt([{ name: 'respuesta', type: 'input', default: 'bar' }]).then(answers => {
assert.equal(answers.respuesta, 'bar');
});
});

it('uses default values when no answer is passed', async function () {
it('uses default values when no answer is passed', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });
helpers.mockPrompt(generator);
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]).then(function (answers) {
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]).then(answers => {
assert.equal(answers.respuesta, 'bar');
});
});

it('supports `null` answer for `list` type', async function () {
it('supports `null` answer for `list` type', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });

helpers.mockPrompt(generator, {
respuesta: null,
});

return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'list', default: 'bar' }]).then(function (answers) {
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'list', default: 'bar' }]).then(answers => {
assert.equal(answers.respuesta, null);
});
});

it('treats `null` as no answer for `input` type', async function () {
it('treats `null` as no answer for `input` type', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });

helpers.mockPrompt(generator, {
respuesta: null,
});

return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]).then(function (answers) {
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'input', default: 'bar' }]).then(answers => {
assert.equal(answers.respuesta, 'bar');
});
});

it('uses `true` as the default value for `confirm` type', async function () {
it('uses `true` as the default value for `confirm` type', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });
helpers.mockPrompt(generator, {});

return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'confirm' }]).then(function (answers) {
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'confirm' }]).then(answers => {
assert.equal(answers.respuesta, true);
});
});

it('supports `false` answer for `confirm` type', async function () {
it('supports `false` answer for `confirm` type', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });
helpers.mockPrompt(generator, { respuesta: false });

return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'confirm' }]).then(function (answers) {
return generator.prompt([{ name: 'respuesta', message: 'foo', type: 'confirm' }]).then(answers => {
assert.equal(answers.respuesta, false);
});
});

it('prefers mocked values over defaults', function () {
return this.generator.prompt([{ name: 'answer', type: 'input', default: 'bar' }]).then(function (answers) {
return this.generator.prompt([{ name: 'answer', type: 'input', default: 'bar' }]).then(answers => {
assert.equal(answers.answer, 'foo');
});
});

it('can be call multiple time on the same generator', async function () {
it('can be call multiple time on the same generator', async () => {
const generator = await environment.instantiate(helpers.createDummyGenerator(), { generatorArgs: [], generatorOptions: {} });
helpers.mockPrompt(generator, { foo: 1 });
helpers.mockPrompt(generator, { foo: 2 });
return generator.prompt({ message: 'bar', name: 'foo' }).then(function (answers) {
return generator.prompt({ message: 'bar', name: 'foo' }).then(answers => {
assert.equal(answers.foo, 2);
});
});
Expand All @@ -148,7 +148,7 @@ describe('yeoman-test', function () {
it('keep prompt method asynchronous', function () {
const spy = mock.fn();

const promise = this.generator.prompt({ name: 'answer', type: 'input' }).then(function () {
const promise = this.generator.prompt({ name: 'answer', type: 'input' }).then(() => {
assert.strictEqual(spy.mock.callCount(), 1);
});

Expand All @@ -157,17 +157,17 @@ describe('yeoman-test', function () {
});
});

describe('.run()', function () {
describe('with a generator', function () {
it('return a RunContext object', function (done) {
describe('.run()', () => {
describe('with a generator', () => {
it('return a RunContext object', done => {
const context = helpers.run(helpers.createDummyGenerator());
assert(context instanceof RunContext);
context.on('end', done);
});
});

describe('with a namespace', function () {
it('return a RunContext object', function (done) {
describe('with a namespace', () => {
it('return a RunContext object', done => {
const context = helpers.run('simple:app').withEnvironment(environment => {
environment.register(require.resolve('./fixtures/generator-simple/app'));
});
Expand All @@ -176,20 +176,20 @@ describe('yeoman-test', function () {
});
});

it('pass settings to RunContext', function () {
it('pass settings to RunContext', () => {
const runContext = helpers.run(helpers.createDummyGenerator(), {
namespace: 'foo',
});
assert.equal(runContext.settings.namespace, 'foo');
});

it('pass envOptions to RunContext', function () {
it('pass envOptions to RunContext', () => {
const environmentOptions = { foo: 2 };
const runContext = helpers.run(helpers.createDummyGenerator(), undefined, environmentOptions);
assert.equal(runContext.envOptions, environmentOptions);
});

it('catch env errors', function (done) {
it('catch env errors', done => {
helpers
.run(
class extends helpers.createDummyGenerator() {
Expand All @@ -203,7 +203,7 @@ describe('yeoman-test', function () {
});
});

it('catch generator emitted errors', function (done) {
it('catch generator emitted errors', done => {
helpers
.run(
class extends helpers.createDummyGenerator() {
Expand All @@ -217,7 +217,7 @@ describe('yeoman-test', function () {
});
});

it('catch generator thrown errors', function (done) {
it('catch generator thrown errors', done => {
helpers
.run(
class extends helpers.createDummyGenerator() {
Expand All @@ -233,14 +233,14 @@ describe('yeoman-test', function () {

// This is a workaround for corner case were an error is not correctly emitted
// See https://github.com/yeoman/generator/pull/1155
it('catch run errors', function (done) {
it('catch run errors', done => {
helpers.run(class extends Generator {}, {}, { catchGeneratorError: true }).on('error', _ => {
done();
});
});

describe('with files', function () {
it('write files to mem-fs', async function () {
describe('with files', () => {
it('write files to mem-fs', async () => {
const runResult = await helpers.run(helpers.createDummyGenerator()).withFiles({ 'foo.txt': 'foo', 'foo.json': { foo: 'bar' } });
expect(runResult.getSnapshot()).toMatchInlineSnapshot(`
{
Expand All @@ -259,7 +259,7 @@ describe('yeoman-test', function () {
`);
});

it('write files with relative path to mem-fs', async function () {
it('write files with relative path to mem-fs', async () => {
const runResult = await helpers
.run(helpers.createDummyGenerator())
.withFiles('sub', { 'foo.txt': 'foo', 'foo.json': { foo: 'bar' } });
Expand All @@ -280,7 +280,7 @@ describe('yeoman-test', function () {
`);
});

it('write string .yo-rc.json to mem-fs', async function () {
it('write string .yo-rc.json to mem-fs', async () => {
const runResult = await helpers.run(helpers.createDummyGenerator()).withYoRc('{"foo": "bar"}');
expect(runResult.getSnapshot()).toMatchInlineSnapshot(`
{
Expand All @@ -292,7 +292,7 @@ describe('yeoman-test', function () {
`);
});

it('write object .yo-rc.json to mem-fs', async function () {
it('write object .yo-rc.json to mem-fs', async () => {
const runResult = await helpers.run(helpers.createDummyGenerator()).withYoRc({ foo: 'bar' });
expect(runResult.getSnapshot()).toMatchInlineSnapshot(`
{
Expand All @@ -307,7 +307,7 @@ describe('yeoman-test', function () {
`);
});

it('merges object .yo-rc.json to mem-fs', async function () {
it('merges object .yo-rc.json to mem-fs', async () => {
const runResult = await helpers.run(helpers.createDummyGenerator()).withYoRc({ foo: 'bar' }).withYoRc({ bar: 'foo' });
expect(runResult.getSnapshot()).toMatchInlineSnapshot(`
{
Expand All @@ -323,7 +323,7 @@ describe('yeoman-test', function () {
`);
});

it('writes object GeneratorConfig to mem-fs', async function () {
it('writes object GeneratorConfig to mem-fs', async () => {
const runResult = await helpers
.run(helpers.createDummyGenerator())
.withYoRcConfig('ns', { foo: 'bar' })
Expand All @@ -346,7 +346,7 @@ describe('yeoman-test', function () {
`);
});

it('write files to mem-fs', async function () {
it('write files to mem-fs', async () => {
const runResult = await helpers
.run(helpers.createDummyGenerator())
.withFiles({ 'foo.txt': 'foo', 'foo.json': { foo: 'bar' } })
Expand All @@ -356,8 +356,8 @@ describe('yeoman-test', function () {
});
});

describe('callbacks', function () {
it('calls in order', async function () {
describe('callbacks', () => {
it('calls in order', async () => {
const order: string[] = [];

const runContext = helpers.run(helpers.createDummyGenerator());
Expand Down
6 changes: 3 additions & 3 deletions test/run-context-environment.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import SimpleApp from './fixtures/generator-simple/app/index.js';
const require = createRequire(import.meta.url);
const __dirname = dirname(fileURLToPath(import.meta.url));

describe('RunContext running environment', function () {
describe('RunContext running environment', () => {
const defaultEnvironmentOptions = { foo: 'bar' };
const defaultRunContextOptions = {};

Expand All @@ -25,7 +25,7 @@ describe('RunContext running environment', function () {
let build = true;
let lookups: LookupOptions[] = [];

beforeEach(async function () {
beforeEach(async () => {
process.chdir(__dirname);

if (!gen) {
Expand All @@ -40,7 +40,7 @@ describe('RunContext running environment', function () {
}
});

afterEach(function () {
afterEach(() => {
process.chdir(__dirname);
context.cleanTestDirectory();
});
Expand Down
Loading

0 comments on commit 05628f4

Please sign in to comment.