Skip to content

Commit

Permalink
patch: update dev mode errors
Browse files Browse the repository at this point in the history
  • Loading branch information
ealush committed Nov 19, 2020
1 parent 54e500f commit 52691b0
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,10 @@ module.exports = {
'prettier',
],
globals: {
__DEV__: true,
__LIB_VERSION__: true,
LIBRARY_NAME: true,
ENV_DEVELOPMENT: true,
LIBRARY_NAME: true,
},
ignorePatterns: ['playground'],
overrides: [
Expand Down
4 changes: 3 additions & 1 deletion packages/n4s/src/lib/transformResult.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ export function validateResult(result, rule) {
}

throwError(
`${rule.name} wrong return value for the rule please check that the return is valid`
__DEV__
? `${rule.name} wrong return value for the rule please check that the return is valid`
: rule.name + 'wrong return value'
);
}

Expand Down
1 change: 1 addition & 0 deletions packages/vest/config/jest/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { packageJson, packageNames } = require('../../../../util');
const { version } = packageJson(packageNames.VEST);
global.LIBRARY_NAME = packageNames.VEST;
global.__LIB_VERSION__ = version;
global.__DEV__ = true;
global.ENV_DEVELOPMENT = true;

// Registers global instance
Expand Down
13 changes: 8 additions & 5 deletions packages/vest/src/core/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import isPromise from 'isPromise';
import { setPending } from 'pending';
import runAsyncTest from 'runAsyncTest';
import bindTestMemo from 'test.memo';
import throwError from 'throwError';

/**
* Runs sync tests - or extracts promise.
Expand Down Expand Up @@ -50,11 +51,13 @@ const register = testObject => {
runAsyncTest(testObject);
}
} catch {
/* FUTURE: throw an error here in dev mode:
* Your test function ${testObject.fieldName} returned
* a value other than `false` or a Promise. Return values
* are not supported and may cause unexpected behavior.
*/
if (__DEV__) {
throwError(
`Your test function ${testObject.fieldName} returned ${JSON.stringify(
result
)}. Only "false" or a Promise are supported. Return values may cause unexpected behavior.`
);
}
}
};

Expand Down
6 changes: 5 additions & 1 deletion packages/vest/src/hooks/group.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import isStringValue from 'isStringValue';
import throwError from 'throwError';

const throwGroupError = value =>
throwError(`group initialization error. Expected "${value}" to be a string.`);
throwError(
__DEV__
? `group initialization error. Expected "${value}" to be a string.`
: 'group name must be a string'
);

/**
* Runs a group callback.
Expand Down
5 changes: 3 additions & 2 deletions packages/vest/src/hooks/warn.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ import throwError from 'throwError';
/**
* @type {String} Error message to display when `warn` gets called outside of a test.
*/
const ERROR_OUTSIDE_OF_TEST =
"warn hook called outside of a test callback. It won't have an effect.";
const ERROR_OUTSIDE_OF_TEST = __DEV__
? "warn hook called outside of a test callback. It won't have an effect."
: 'warn called outside of a test.';

/**
* Sets a running test to warn only mode.
Expand Down

0 comments on commit 52691b0

Please sign in to comment.