Skip to content

Commit

Permalink
Improve Typescript compatibility (#14)
Browse files Browse the repository at this point in the history
* move javascript tests to their own directory

* add basic typescript integration tests

* remove build artifacts
  • Loading branch information
maboesanman committed Mar 12, 2020
1 parent 7f8791a commit 8f87866
Show file tree
Hide file tree
Showing 38 changed files with 480 additions and 156 deletions.
14 changes: 8 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
node_modules
dist
coverage
integration-tests/jest/givens.tgz
integration-tests/jest/package-lock.json
integration-tests/mocha/givens.tgz
integration-tests/mocha/package-lock.json
integration-tests/jasmine/givens.tgz
integration-tests/jasmine/package-lock.json
integration-tests/javascript/jest/givens.tgz
integration-tests/javascript/jest/package-lock.json
integration-tests/javascript/mocha/givens.tgz
integration-tests/javascript/mocha/package-lock.json
integration-tests/javascript/jasmine/givens.tgz
integration-tests/javascript/jasmine/package-lock.json
integration-tests/typescript/jest/givens.tgz
integration-tests/typescript/jest/package-lock.json
16 changes: 10 additions & 6 deletions clean.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
rm -rf node_modules
rm -rf dist
rm -rf coverage
rm -rf integration-tests/jest/node_modules
rm -f integration-tests/jest/givens.tgz
rm -rf integration-tests/mocha/node_modules
rm -f integration-tests/mocha/givens.tgz
rm -rf integration-tests/jasmine/node_modules
rm -f integration-tests/jasmine/givens.tgz

rm -rf integration-tests/javascript/jest/node_modules
rm -f integration-tests/javascript/jest/givens.tgz
rm -rf integration-tests/javascript/mocha/node_modules
rm -f integration-tests/javascript/mocha/givens.tgz
rm -rf integration-tests/javascript/jasmine/node_modules
rm -f integration-tests/javascript/jasmine/givens.tgz

rm -rf integration-tests/typescript/jest/node_modules
rm -f integration-tests/typescript/jest/givens.tgz
6 changes: 0 additions & 6 deletions integration-tests/jasmine/build-givens.sh

This file was deleted.

File renamed without changes.
6 changes: 6 additions & 0 deletions integration-tests/javascript/jasmine/build-givens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd ./../../../
npm pack
for f in *.tgz; do
mv $f integration-tests/javascript/jasmine/givens.tgz
done
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions integration-tests/javascript/jest/build-givens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd ./../../../
npm pack
for f in *.tgz; do
mv $f integration-tests/javascript/jest/givens.tgz
done
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 6 additions & 0 deletions integration-tests/javascript/mocha/build-givens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd ./../../../
npm pack
for f in *.tgz; do
mv $f integration-tests/javascript/mocha/givens.tgz
done
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions integration-tests/jest/build-givens.sh

This file was deleted.

6 changes: 0 additions & 6 deletions integration-tests/mocha/build-givens.sh

This file was deleted.

6 changes: 6 additions & 0 deletions integration-tests/typescript/jest/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
module.exports = {
plugins: ["jest"],
env: {
jest: true
},
};
6 changes: 6 additions & 0 deletions integration-tests/typescript/jest/build-givens.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash
cd ./../../../
npm pack
for f in *.tgz; do
mv $f integration-tests/typescript/jest/givens.tgz
done
8 changes: 8 additions & 0 deletions integration-tests/typescript/jest/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
preset: 'ts-jest',
testEnvironment: 'node',
verbose: true,
setupFilesAfterEnv: [
'givens/setup.js',
],
};
16 changes: 16 additions & 0 deletions integration-tests/typescript/jest/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "givens-integration-tests-jest",
"version": "1.0.0",
"scripts": {
"test": "jest",
"preinstall": "./build-givens.sh",
"lint": "eslint test/**.*"
},
"devDependencies": {
"eslint": "^6.8.0",
"eslint-config-airbnb-base": "^14.0.0",
"eslint-plugin-jest": "^23.6.0",
"givens": "file:givens.tgz",
"jest": "^25.1.0"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`illegal call location in test breaks 1`] = `"givens: cannot call givens from a test"`;

exports[`with recursive given variables blows up 1`] = `
"givens: recursive variable recursive1 detected
trace: recursive1 => recursive2 => recursive1"
`;
85 changes: 85 additions & 0 deletions integration-tests/typescript/jest/test/errors.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
import assert from 'assert';
import getGiven from 'givens';

const given = getGiven();

describe('illegal prop', () => {
assert.throws(
() => given('__props__', () => 'value'),
(err) => err.message === 'givens: key "__props__" is not allowed',
);

it('does stuff', () => {
expect(true);
});
});

describe('illegal call location', () => {
describe('in beforeEach method', () => {
beforeEach(() => {
assert.throws(
() => given('test', () => 'foo'),
(err) => err.message === 'givens: cannot call givens from a lifecycle hook',
);
});

it('breaks', () => {});
});

describe('in afterEach method', () => {
afterEach(() => {
assert.throws(
() => given('test', () => 'foo'),
(err) => err.message === 'givens: cannot call givens from a lifecycle hook',
);
});

it('breaks', () => {});
});

describe('in beforeAll method', () => {
beforeAll(() => {
assert.throws(
() => given('test', () => 'foo'),
(err) => err.message === 'givens: cannot call givens from a lifecycle hook',
);
});

it('breaks', () => {});
});

describe('in afterAll method', () => {
afterAll(() => {
assert.throws(
() => given('test', () => 'foo'),
(err) => err.message === 'givens: cannot call givens from a lifecycle hook',
);
});

it('breaks', () => {});
});

describe('in test', () => {
it('breaks', () => {
expect(() => given('test', () => 'foo')).toThrowErrorMatchingSnapshot();
});
});
});

describe('with recursive given variables', () => {
given('recursive1', () => {
const string1 = 'recursive1 => ';
const string2 = given.recursive2;
return string1 + string2;
});
given('recursive2', () => {
const string1 = 'recursive2 => ';
const string2 = given.recursive1;
return string1 + string2;
});
given('nonRecursive', () => given.recursive1);

it('blows up', () => {
expect(() => given.nonRecursive).toThrowErrorMatchingSnapshot();
});
});
61 changes: 61 additions & 0 deletions integration-tests/typescript/jest/test/given-default.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import assert from 'assert';
import getGiven from 'givens';

const given = getGiven();

describe('basic overriding behavior', () => {
given('var1', () => 'initial value');

given('var2', () => `the value is: ${given.var1}`);

it('has initial value', () => {
expect(given.var2).toEqual('the value is: initial value');
});

describe('with new value', () => {
given('var1', () => 'overridden value');

it('has overridden value', () => {
expect(given.var2).toEqual('the value is: overridden value');
});
});

it('has initial value again', () => {
expect(given.var2).toEqual('the value is: initial value');
});
});

describe('basic caching behavior', () => {
given('var', () => ({ value: 'initial' }));
given('random', () => Math.random());

test('it caches value', () => {
given.var.value = 'new';
expect(given.var.value).toBe('new');
});

test('random cache test', () => {
expect(given.random).toEqual(given.random);
});

describe('with beforeEach', () => {
beforeEach(() => {
given.var.value = 'new';
});

test('it caches value', () => {
expect(given.var.value).toBe('new');
});
});

describe('with afterEach', () => {
afterEach(() => {
assert.equal(given.var.value, 'new');
});

test('it caches value', () => {
expect(given.var.value).toBe('initial');
given.var.value = 'new';
});
});
});
68 changes: 68 additions & 0 deletions integration-tests/typescript/jest/test/given-typed.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import assert from 'assert';
import getGiven from 'givens';

interface myVars {
var1: string;
var2: string;
var: { value: string };
random: number;
}

const given = getGiven<myVars>();

describe('basic overriding behavior', () => {
given('var1', () => 'initial value');

given('var2', () => `the value is: ${given.var1}`);

it('has initial value', () => {
expect(given.var2).toEqual('the value is: initial value');
});

describe('with new value', () => {
given('var1', () => 'overridden value');

it('has overridden value', () => {
expect(given.var2).toEqual('the value is: overridden value');
});
});

it('has initial value again', () => {
expect(given.var2).toEqual('the value is: initial value');
});
});

describe('basic caching behavior', () => {
given('var', () => ({ value: 'initial' }));
given('random', () => Math.random());

test('it caches value', () => {
given.var.value = 'new';
expect(given.var.value).toBe('new');
});

test('random cache test', () => {
expect(given.random).toEqual(given.random);
});

describe('with beforeEach', () => {
beforeEach(() => {
given.var.value = 'new';
});

test('it caches value', () => {
expect(given.var.value).toBe('new');
});
});

describe('with afterEach', () => {
afterEach(() => {
assert.equal(given.var.value, 'new');
});

test('it caches value', () => {
expect(given.var.value).toBe('initial');
given.var.value = 'new';
});
});
});
6 changes: 6 additions & 0 deletions integration-tests/typescript/jest/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compilerOptions": {
"esModuleInterop": true,
"strict": true
}
}
Loading

0 comments on commit 8f87866

Please sign in to comment.