Skip to content

Commit 4eca550

Browse files
Add node 14 support and update Github Action (#133)
* gh action node 14 support * fix tests for engines lower than 12 * add beta tag to setup node v2 * change engine version * remove node 8 from ci workflow matrix
1 parent 59ab4ab commit 4eca550

File tree

5 files changed

+29
-21
lines changed

5 files changed

+29
-21
lines changed

.github/workflows/nodejs.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [8.x, 10.x, 12.x]
12+
node-version: ['10.x', '12.x', '14.x']
1313

1414
steps:
15-
- uses: actions/checkout@v1
15+
- uses: actions/checkout@v2
1616
- name: Use Node.js ${{ matrix.node-version }}
17-
uses: actions/setup-node@v1
17+
uses: actions/setup-node@v2-beta
1818
with:
1919
node-version: ${{ matrix.node-version }}
20-
- name: npm install, build, and test
20+
- name: install dependencies, build and test
2121
run: |
22-
npm install
22+
npm ci
2323
npm run build --if-present
2424
npm test
2525
env:

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
"url": "https://github.com/ffMathy/FluffySpoon.JavaScript.Testing.Faking/issues"
2727
},
2828
"engines": {
29-
"node": ">=8"
29+
"node": ">=10"
3030
},
3131
"main": "dist/src/index.js",
3232
"typings": "./dist/src/index.d.ts",

spec/returns.spec.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import test from 'ava';
2-
import { Substitute, Arg } from '../src';
32
import { inspect } from 'util'
43

4+
import { Substitute, Arg } from '../src';
5+
import { getCorrectConstructorDescriptor } from './util/compatibility';
6+
57
interface Calculator {
68
add(a: number, b: number): number;
79
multiply(a: number, b?: number): number;
@@ -28,7 +30,7 @@ test('returns a primitive value for method with specific arguments', t => {
2830

2931
t.is(calculator.add(1, 1), 2);
3032
t.is(calculator.add(1, 1), 2);
31-
t.is(inspect(noResult.constructor), '[Function: SubstituteJS]');
33+
t.is(inspect(noResult.constructor), `[${getCorrectConstructorDescriptor()} SubstituteJS]`);
3234
});
3335

3436
test('returns a primitive value for method with specific arguments where the last argument is optional', t => {
@@ -46,8 +48,8 @@ test('returns a primitive value for method with specific arguments where the las
4648
const noResult = calculator.multiply(2, 2);
4749
const noResult2 = calculator.multiply(0);
4850

49-
t.is(inspect(noResult.constructor), '[Function: SubstituteJS]');
50-
t.is(inspect(noResult2.constructor), '[Function: SubstituteJS]');
51+
t.is(inspect(noResult.constructor), `[${getCorrectConstructorDescriptor()} SubstituteJS]`);
52+
t.is(inspect(noResult2.constructor), `[${getCorrectConstructorDescriptor()} SubstituteJS]`);
5153
});
5254

5355
test('returns a primitive value for method with specific and conditional arguments', t => {
@@ -97,7 +99,7 @@ test('returns a promise for method with specific arguments', async t => {
9799
const noResult = calculator.heavyOperation(1, 1, 1);
98100

99101
t.is(result, true);
100-
t.is(inspect(noResult.constructor), '[Function: SubstituteJS]');
102+
t.is(inspect(noResult.constructor), `[${getCorrectConstructorDescriptor()} SubstituteJS]`);
101103
});
102104

103105
test('returns a promise for method with specific and conditional arguments', async t => {
@@ -151,7 +153,7 @@ test('returns a primitive value on a property', t => {
151153

152154
t.is(calculator.isEnabled, true);
153155
t.is(calculator.isEnabled, true);
154-
t.is(inspect(noResult.constructor), '[Function: SubstituteJS]');
156+
t.is(inspect(noResult.constructor), `[${getCorrectConstructorDescriptor()} SubstituteJS]`);
155157
});
156158

157159
test('returns a promise on a property', async t => {

spec/util/compatibility.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const getCorrectConstructorDescriptor = () => {
2+
const nodeVersionLowerThan12 = Number(process.versions.node.split('.')[0]) < 12;
3+
return nodeVersionLowerThan12 ?
4+
'Function:' :
5+
'class';
6+
};

src/SubstituteBase.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,30 @@ export class SubstituteJS {
1010
return typeof this._lastRegisteredSubstituteJSMethodOrProperty === 'undefined' ? 'root' : this._lastRegisteredSubstituteJSMethodOrProperty;
1111
}
1212
[Symbol.toPrimitive]() {
13-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
13+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
1414
}
1515
[Symbol.toStringTag]() {
16-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
16+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
1717
}
1818
[Symbol.iterator]() {
19-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
19+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
2020
}
2121
[inspect.custom]() {
22-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
22+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
2323
}
2424
valueOf() {
25-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
25+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
2626
}
2727
$$typeof() {
28-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
28+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
2929
}
3030
toString() {
31-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
31+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
3232
}
3333
inspect() {
34-
return `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
34+
return `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
3535
}
36-
length = `[Function: ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
36+
length = `[class ${this.constructor.name}] -> ${this.lastRegisteredSubstituteJSMethodOrProperty}`;
3737
}
3838

3939
enum SubstituteExceptionTypes {

0 commit comments

Comments
 (0)