Skip to content

Commit 92cd1d7

Browse files
authored
feat(config): add option to disable cache between files as a workaround until #101 is completed
* add cache option * update circle ci badge
1 parent 98691f9 commit 92cd1d7

34 files changed

+140
-48
lines changed

README.md

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,8 @@
11
# Ts Auto Mock
2-
[![CircleCI](https://circleci.com/gh/uittorio/ts-auto-mock/tree/master.svg?style=svg)](https://circleci.com/gh/uittorio/ts-auto-mock/tree/master)
3-
[![Greenkeeper badge](https://badges.greenkeeper.io/uittorio/ts-auto-mock.svg)](https://greenkeeper.io/)
2+
[![CircleCI](https://circleci.com/gh/Typescript-TDD/ts-auto-mock.svg?style=svg)](https://circleci.com/gh/Typescript-TDD/ts-auto-mock)
43
[![npm version](https://badge.fury.io/js/ts-auto-mock.svg)](https://badge.fury.io/js/ts-auto-mock)
54
[![Downloads](https://img.shields.io/npm/dt/ts-auto-mock.svg)](https://www.npmjs.com/package/ts-auto-mock)
65

7-
86
![slack](docs/slack_small.png) Need help? Join us on Slack [link](https://join.slack.com/t/typescripttdd/shared_invite/enQtODM3MzExODE0NTk2LTNmYzRhM2M1ZDc5ODVkMmVlZWFjMTM4ZDFhNWU2NDdiYWY1MGMxZjE2ZDE0ZDZlYjY1MTkyYjRhYTQ1NjA1MWQ)
97

108

@@ -114,16 +112,42 @@ The library allows you to extends some functionality to work nicely with framewo
114112
tsAutoMockTransformer(program: ts.Program, options: TsAutoMockOptions)
115113

116114
interface TsAutoMockOptions {
117-
debug: boolean | 'file' | 'console'
115+
debug: boolean | 'file' | 'console';
116+
cacheBetweenTests: boolean;
118117
}
119118
```
120119
options:
121120

122-
| Name | Default | Description |
123-
| ------------- | --------------------------- | --------------- |
124-
| `debug` | `false` | When set to `true` or `console` it will log to the console
125-
| | | When set to `file` it will log to a file (tsAutoMock.log)
121+
| Name | Default | Description |
122+
| ------------- | --------------------------- | --------------- |
123+
| `debug` | `false` | When set to `true` or `console` it will log to the console
124+
| | | When set to `file` it will log to a file (tsAutoMock.log)
125+
| `cacheBetweenTests` | `true` | When set to `true` it will reuse mocks between different tests
126+
| | | When set to `false` it create new mocks for each different tests
127+
128+
#### Debug
129+
We currently support
130+
- Logs for [not supported types](docs/NOT_SUPPORTED.md)
131+
It will log any not supported type automatically converted to null.
132+
This is useful to report an issue or to investigate a potential bug
133+
134+
#### cacheBetweenTests
135+
One of the main functionality of ts auto mock is to generate mocks and cache them.
136+
137+
Mocks are currently created in the test file making tests to depend to each other
138+
139+
Example:
140+
- test1.test.ts has a createMock of Interface.
141+
- test2.test.ts has a createMock of Interface.
142+
- test1.test.ts will have the registration of Interface mock
143+
- test2.test.ts will have a registration import.
144+
145+
If test2 run in a different context than test1 it will not be able to access to the same mock.
146+
147+
Set this property to false when your test run in different context.
126148

149+
We are working on an [issue](https://github.com/Typescript-TDD/ts-auto-mock/issues/101) to make sure tests do not depend to each other but they will still take advance of a cache system
150+
127151
## [Changelog](CHANGELOG.md)
128152

129153
## Authors

config/karma/karma.config.base.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ const ProcessService = require('../process/process');
33
process.env.CHROME_BIN = require('puppeteer').executablePath();
44

55
module.exports = function(config, url) {
6-
const debug = ProcessService(process).getArgument('DEBUG');
6+
const processService = ProcessService(process);
7+
const debug = processService.getArgument('DEBUG');
8+
const disableCache = processService.getArgument('DISABLECACHE');
79

810
return {
911
basePath: '',
1012
frameworks: ['jasmine'],
11-
webpack: webpackConfig(debug),
13+
webpack: webpackConfig(debug, disableCache),
1214
webpackMiddleware: {
1315
stats: 'errors-only'
1416
},
@@ -38,5 +40,4 @@ module.exports = function(config, url) {
3840
browsers: ['ChromeHeadless'],
3941
singleRun: true
4042
}
41-
4243
};
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
const karmaBaseConfig = require('./karma.config.base');
2+
3+
module.exports = function(config) {
4+
const karmaConfig = karmaBaseConfig(config, "../../test/frameworkContext/context.ts");
5+
6+
config.set(karmaConfig);
7+
};
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const karmaBaseConfig = require('./karma.config.base');
22

33
module.exports = function(config) {
4-
const karmaConfig = karmaBaseConfig(config, "../../test/framework/contextDeprecated.ts");
4+
const karmaConfig = karmaBaseConfig(config, "../../test/frameworkContext/contextDeprecated.ts");
55

66
config.set(karmaConfig);
77
};
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
const karmaBaseConfig = require('./karma.config.base');
22

33
module.exports = function(config) {
4-
const karmaConfig = karmaBaseConfig(config, "../../test/framework/context.ts");
4+
const karmaConfig = karmaBaseConfig(config, "../../test/framework/**/*.test.ts");
55

66
config.set(karmaConfig);
7-
};
7+
};

config/process/process.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ function ProcessService(process) {
77
processArguments.forEach((argument) => {
88
const values = argument.split('=');
99
if (argumentName === values[0])
10-
valueToFind = values[1];
10+
valueToFind = values[1];
1111
});
1212

1313
return valueToFind;

config/test/webpack.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
const transformer = require('../../dist/transformer');
22
const path = require('path');
33

4-
module.exports = function(debug) {
4+
module.exports = function (debug, disableCache) {
55
return {
66
mode: "development",
7-
resolve: {
8-
extensions: ['.ts', '.js'],
9-
alias: {
10-
['ts-auto-mock']: path.join(__dirname, '../../dist'),
11-
['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'),
12-
['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'),
13-
}
14-
},
7+
resolve: {
8+
extensions: ['.ts', '.js'],
9+
alias: {
10+
['ts-auto-mock']: path.join(__dirname, '../../dist'),
11+
['ts-auto-mock/repository']: path.join(__dirname, '../../dist/repository'),
12+
['ts-auto-mock/extension']: path.join(__dirname, '../../dist/extension'),
13+
}
14+
},
1515
module: {
1616
rules: [
1717
{
@@ -25,9 +25,10 @@ module.exports = function(debug) {
2525
options: {
2626
configFileName: "test/tsconfig.json",
2727
getCustomTransformers: (program) => ({
28-
before: [ transformer.default(program, {
29-
debug: debug ? 'file' : false
30-
}) ]
28+
before: [transformer.default(program, {
29+
debug: debug ? 'file' : false,
30+
cacheBetweenTests: disableCache !== 'true'
31+
})]
3132
})
3233
}
3334
}

package.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,13 @@
66
"build:transformer": "webpack --config config/modules/transformer/webpack.js",
77
"build:modules": "webpack --config config/modules/webpack.js",
88
"build": "npm run build:modules && npm run build:transformer",
9-
"test": "npm run test:transformer && npm run test:framework && npm run test:frameworkDeprecated && npm run test:unit",
10-
"test:debug": "npm run test:transformer:debug && npm run test:framework:debug && npm run test:frameworkDeprecated:debug && npm run test:unit",
11-
"test:transformer": "karma start config/karma/karma.config.transformer.js",
9+
"test": "npm run test:transformer && npm run test:framework:context && npm run test:framework && npm run test:frameworkDeprecated && npm run test:unit",
1210
"test:unit": "karma start config/karma/karma.config.unit.js",
11+
"test:transformer": "karma start config/karma/karma.config.transformer.js",
1312
"test:playground": "karma start config/karma/karma.config.transformer.playground.js",
14-
"test:framework": "karma start config/karma/karma.config.framework.js",
13+
"test:framework:context": "karma start config/karma/karma.config.framework.context.js",
1514
"test:frameworkDeprecated": "karma start config/karma/karma.config.framework.deprecated.js",
16-
"test:transformer:debug": "npm run test:transformer DEBUG=true",
17-
"test:framework:debug": "npm run test:framework DEBUG=true",
18-
"test:frameworkDeprecated:debug": "npm run test:frameworkDeprecated DEBUG=true",
15+
"test:framework": "karma start config/karma/karma.config.framework.js DISABLECACHE=true",
1916
"version": "conventional-changelog -p angular -i CHANGELOG.md -s && git add CHANGELOG.md",
2017
"copyForPublish": "cp -rf package.json README.md CHANGELOG.md dist",
2118
"preparePublish": "npm run build && npm run copyForPublish",

src/logger/logger.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as winston from 'winston';
22
import { AbstractConfigSet } from 'winston/lib/winston/config';
3-
import { GetTsAutoMockDebugOptions, TsAutoMockDebugOptions } from '../options/options';
3+
import { GetTsAutoMockDebugOptions, TsAutoMockDebugOptions } from '../options/debug';
44
import { ConsoleLogger } from './consoleLogger';
55
import { FileLogger } from './fileLogger';
66
import { ILogger } from './logger.interface';

src/options/cache.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { GetOptionByKey } from './options';
2+
3+
export type TsAutoMockCacheOptions = boolean;
4+
5+
export function GetTsAutoMockCacheOptions(): TsAutoMockCacheOptions {
6+
return GetOptionByKey('cacheBetweenTests');
7+
}

0 commit comments

Comments
 (0)