Skip to content

Commit

Permalink
refactor: be more descriptive than "blah", "foo", "bar" in tests
Browse files Browse the repository at this point in the history
- instead of random names (which are bad practice), be very explicit
  about what the variables _should_ be
- also add comments to some of the regression tests that didn't have
  any to describe them

- similarly, when testing dev only logging, say that directly
  - and, in this case, instead of using an unnecessary swear word
    - the third contributor PR to TSDX removed some similar swear words
      in the templates
      - these were changed to "boop" and now similarly changed to be
        more descriptive
        - which is better practice anyway, not encouraging bad practices
          via the templates, and should also be easier to understand for
          newcomers

- similarly, intead of "blah" and "works" in template tests, actually
  describe what the tests do
  - similarly encourage better practices in the tests

- also rename template tests from "blah.test.ts" to "index.test.ts"
  because they test "index.ts" and it's common convention to name them
  the same

- and fix a leftover "describe('it')" in the react template when it
  should be "describe('Thing')" which the storybook template has
  - "it" is also confusing when used together with the Jest "it" global
  - could use something better than "Thing" as well (e.g.
    "SomeComponent"), but don't want to dig through and re-test the
    Storybook pieces right now
  • Loading branch information
agilgur5 committed Oct 14, 2020
1 parent fcd2639 commit 26c56a7
Show file tree
Hide file tree
Showing 17 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion templates/basic/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ This is the folder structure we set up for you:
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
index.test.tsx # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
Expand Down
2 changes: 1 addition & 1 deletion templates/basic/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('boop');
console.log('dev only output');
}
return a + b;
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { sum } from '../src';

describe('blah', () => {
it('works', () => {
describe('sum', () => {
it('adds two numbers together', () => {
expect(sum(1, 1)).toEqual(2);
});
});
2 changes: 1 addition & 1 deletion templates/react-with-storybook/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ This is the folder structure we set up for you:
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
index.test.tsx # EDIT THIS
/stories
Thing.stories.tsx # EDIT THIS
/.storybook
Expand Down
2 changes: 1 addition & 1 deletion templates/react/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ This is the folder structure we set up for you:
/src
index.tsx # EDIT THIS
/test
blah.test.tsx # EDIT THIS
index.test.tsx # EDIT THIS
.gitignore
package.json
README.md # EDIT THIS
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as React from 'react';
import * as ReactDOM from 'react-dom';
import { Thing } from '../src';

describe('it', () => {
describe('Thing', () => {
it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<Thing />, div);
Expand Down
1 change: 0 additions & 1 deletion test/e2e/fixtures/build-default/src/foo.ts

This file was deleted.

4 changes: 2 additions & 2 deletions test/e2e/fixtures/build-default/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export { testGenerator } from './syntax/generator';
export { kebabCase } from 'lodash';
export { merge, mergeAll } from 'lodash/fp';

export { foo } from './foo';
export { returnsTrue } from './returnsTrue';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
console.log('dev only output');
}
return a + b;
};
2 changes: 2 additions & 0 deletions test/e2e/fixtures/build-default/src/returnsTrue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// this just ensure a simple import works
export const returnsTrue = () => true;
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// regression test for nullish coalescing syntax
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#nullish-coalescing

const bar = () => {};
const foo = false;
export const x = foo ?? bar();
const someFunc = () => {};
const someFalse = false;
const shouldBeFalse = someFalse ?? someFunc();
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// regression test for optional chaining syntax
// https://www.typescriptlang.org/docs/handbook/release-notes/typescript-3-7.html#optional-chaining

export const foo = (foo?: { bar: string }) => foo?.bar || 'bar';
const someObj: { someOptionalString?: string } = {};
const shouldBeBar = someObj?.someOptionalString || 'bar';
2 changes: 1 addition & 1 deletion test/e2e/fixtures/build-withTsconfig/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
console.log('dev only output');
}
return a + b;
};
4 changes: 2 additions & 2 deletions test/e2e/tsdx-build-default.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ describe('tsdx build :: zero-config defaults', () => {
const output = execWithCache('node ../dist/index.js build');

const lib = require(`../../${stageName}/dist`);
expect(lib.foo()).toBe('bar');
expect(lib.__esModule).toBe(true);
expect(lib.returnsTrue()).toBe(true);
expect(lib.__esModule).toBe(true); // test that ESM -> CJS interop was output

expect(output.code).toBe(0);
});
Expand Down
2 changes: 1 addition & 1 deletion test/integration/fixtures/build-options/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ warning(true, 'warning - water is wet');

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
console.log('dev only output');
}
return a + b;
};
2 changes: 1 addition & 1 deletion test/integration/fixtures/build-withBabel/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ export { Title } from './styled';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
console.log('dev only output');
}
return a + b;
};
2 changes: 1 addition & 1 deletion test/integration/fixtures/build-withConfig/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import './index.css';

export const sum = (a: number, b: number) => {
if ('development' === process.env.NODE_ENV) {
console.log('fuck');
console.log('dev only output');
}
return a + b;
};

0 comments on commit 26c56a7

Please sign in to comment.