Skip to content

Commit

Permalink
test adjusts
Browse files Browse the repository at this point in the history
  • Loading branch information
mshima committed May 11, 2023
1 parent 67df8e4 commit a6668b3
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 43 deletions.
8 changes: 6 additions & 2 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
{
"debug.javascript.terminalOptions": {
"skipFiles": ["node_modules/**", "dist/**"]
},
"mochaExplorer.logpanel": true,
"mochaExplorer.files": ["test/*.{js,cjs,mjs,ts,cts,mts}"],
"mochaExplorer.files": ["test/*.test.ts"],
"mochaExplorer.ui": "tdd",
"mochaExplorer.configFile": ".mocharc.cjs",
"mochaExplorer.nodeArgv": ["--loader=@node-loaders/auto"]
"mochaExplorer.require": "esmocha/mocha",
"mochaExplorer.nodeArgv": ["--loader=esmocha/loader"]
}
3 changes: 3 additions & 0 deletions .xo-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
"files": "test/*",
"rules": {
"max-nested-callbacks": "off",
"@typescript-eslint/no-empty-function": "off",
"@typescript-eslint/no-unused-expressions": "off",
"@typescript-eslint/restrict-plus-operands": "off",
"@typescript-eslint/naming-convention": "off"
}
}
Expand Down
36 changes: 20 additions & 16 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
"@types/semver": "^7.3.13",
"@types/sinon": "^10.0.14",
"@types/text-table": "^0.2.2",
"@yeoman/transform": "^0.2.1",
"c8": "^7.13.0",
"cpy-cli": "^4.2.0",
"esmocha": "^1.0.1",
Expand All @@ -84,7 +85,6 @@
"prettier": "^2.8.8",
"prettier-plugin-packagejson": "^2.4.3",
"sinon": "^15.0.4",
"through2": "^4.0.2",
"tui-jsdoc-template": "^1.2.2",
"typescript": "^5.0.4",
"xo": "^0.54.2",
Expand Down
30 changes: 14 additions & 16 deletions test/base.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import process from 'node:process';
import { Buffer } from 'node:buffer';
import _ from 'lodash';
import { spy as sinonSpy, fake as sinonFake, assert as sinonAssert } from 'sinon';
import through from 'through2';
import { passthrough } from '@yeoman/transform';
import assert from 'yeoman-assert';
import YeomanEnvironment from 'yeoman-environment';
import helpers, { TestAdapter } from 'yeoman-test';
Expand Down Expand Up @@ -293,7 +293,7 @@ describe('Base', () => {
const spy1 = sinonSpy();
const spy2 = sinonSpy();

TestGenerator.prototype.first = () => {
TestGenerator.prototype.first = async () => {
return new Promise(resolve => {
setTimeout(() => {
spy1();
Expand All @@ -312,7 +312,7 @@ describe('Base', () => {
});

it('handle failing promises as errors', function (done) {
TestGenerator.prototype.failing = () => {
TestGenerator.prototype.failing = async () => {
return new Promise((resolve, reject) => {
reject(new Error('some error'));
});
Expand All @@ -326,7 +326,7 @@ describe('Base', () => {
testGen.run().catch(() => {});
});

it('throws if no method is available', function () {
it('throws if no method is available', async function () {
const gen = new (class extends Base {})([], {
resolved: 'generator-ember/all/index.js',
namespace: 'dummy',
Expand All @@ -338,7 +338,7 @@ describe('Base', () => {
});
});

it('will run non-enumerable methods', function () {
it('will run non-enumerable methods', async function () {
class Generator extends Base {}

Object.defineProperty(Generator.prototype, 'nonenumerable', {
Expand Down Expand Up @@ -1057,15 +1057,15 @@ describe('Base', () => {
it('is updated when destinationRoot change', function () {
sinonSpy(Dummy.prototype, '_getStorage');
dummy.destinationRoot('foo');
// eslint-disable-next-line no-unused-expressions

dummy.config;
assert.equal(Dummy.prototype._getStorage.callCount, 1);
dummy.destinationRoot();
// eslint-disable-next-line no-unused-expressions

dummy.config;
assert.equal(Dummy.prototype._getStorage.callCount, 1);
dummy.destinationRoot('foo');
// eslint-disable-next-line no-unused-expressions

dummy.config;
assert.equal(Dummy.prototype._getStorage.callCount, 2);
Dummy.prototype._getStorage.restore();
Expand Down Expand Up @@ -1111,14 +1111,12 @@ describe('Base', () => {
this.fs.write(filepath, 'not correct');

this.queueTransformStream(
through.obj((file, enc, cb) => {
passthrough(file => {
file.contents = Buffer.from('a');
cb(null, file);
}),
).queueTransformStream(
through.obj((file, enc, cb) => {
passthrough(file => {
file.contents = Buffer.from(file.contents.toString() + 'b');
cb(null, file);
}),
);
};
Expand All @@ -1133,13 +1131,11 @@ describe('Base', () => {
this.fs.write(filepath, 'not correct');

this.queueTransformStream([
through.obj((file, enc, cb) => {
passthrough(file => {
file.contents = Buffer.from('a');
cb(null, file);
}),
through.obj((file, enc, cb) => {
passthrough(file => {
file.contents = Buffer.from(file.contents.toString() + 'b');
cb(null, file);
}),
]);
};
Expand Down Expand Up @@ -1221,6 +1217,7 @@ describe('Base', () => {
isFirstEndEvent = false;
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
generatorOnce.run();
});

Expand All @@ -1246,6 +1243,7 @@ describe('Base', () => {
'skip-install': true,
});

// eslint-disable-next-line @typescript-eslint/no-floating-promises
generatorEnd.run();
});
});
Expand Down
1 change: 1 addition & 0 deletions test/deprecate.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable import/no-named-as-default-member */
import assert from 'node:assert';
import chalk from 'chalk';
import sinon from 'sinon';
Expand Down
3 changes: 1 addition & 2 deletions test/environment.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,9 @@ describe('Generator with environment version', () => {

describe('#prompt with storage', () => {
it('with compatible environment', function () {
const self = this;
this.getVersionStub.withArgs().returns('3.0.0');
this.getVersionStub.withArgs('inquirer').returns('7.1.0');
return self.dummy.prompt([], self.dummy.config);
return this.dummy.prompt([], this.dummy.config);
});
});
});
Expand Down
5 changes: 3 additions & 2 deletions test/fs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import assert from 'node:assert';
import path from 'node:path';
import { stub as sinonStub } from 'sinon';
import Environment from 'yeoman-environment';
import { spyOn } from 'jest-mock';
import { esmocha } from 'esmocha';
import BaseGenerator from '../src/generator.js';
import Base from './utils.js';

Expand All @@ -24,7 +24,7 @@ describe('generators.Base (actions/fs)', () => {
beforeEach(function () {
returns = {};
this.base = new BaseGenerator({ namespace: 'foo', help: true });
spyOn(this.base, 'config', 'get').mockReturnValue({
esmocha.spyOn(this.base, 'config', 'get').mockReturnValue({
getAll() {
return configGetAll;
},
Expand Down Expand Up @@ -112,6 +112,7 @@ describe('generators.Base (actions/fs)', () => {
const passedArg3 = {};
const passedArg4 = { foo: 'bar' };

// eslint-disable-next-line @typescript-eslint/no-loop-func
describe(`#${operation.name}`, () => {
let returnValue;
let expectedReturn;
Expand Down
5 changes: 4 additions & 1 deletion test/generators.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ describe('Generators module', () => {
});

it('should expose yoGeneratorVersion', function () {
assert(semver.valid(this.generator.yoGeneratorVersion), `Not valid version ${this.generator.yoGeneratorVersion}`);
assert(
semver.valid(this.generator.yoGeneratorVersion),
`Not valid version ${this.generator.yoGeneratorVersion as string}`,
);
});

it('is an EventEmitter', function (done) {
Expand Down
3 changes: 1 addition & 2 deletions test/spawn-command.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { expect } from 'expect';
import { mock, restoreAllMocks, fn, importMock } from 'esmocha';
import { expect, mock, restoreAllMocks, fn, importMock } from 'esmocha';

const execa = await mock('execa');
const { default: Generator } = await importMock('../src/index.js', { execa });
Expand Down
1 change: 0 additions & 1 deletion test/storage.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
/* eslint-disable @typescript-eslint/no-empty-function */
import assert from 'node:assert';
import fs from 'node:fs';
import os from 'node:os';
Expand Down

0 comments on commit a6668b3

Please sign in to comment.