forked from looker/viz-radial_gauge-marketplace
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add jest for unit testing (#11)
- Loading branch information
Showing
8 changed files
with
1,829 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
GIT_ROOT_DIR=$(git rev-parse --show-toplevel) | ||
|
||
# Installs yarn if it is not already installed. | ||
function looker::install_yarn() { | ||
if command -v yarn &> /dev/null; then | ||
npm install -g yarn | ||
fi | ||
} | ||
|
||
# Configures the project if the user has not already done so. | ||
function looker::configure() { | ||
looker::install_yarn | ||
pushd "$GIT_ROOT_DIR" &> /dev/null | ||
if [[ ! -d "$GIT_ROOT_DIR/node_modules" ]]; then | ||
yarn | ||
fi | ||
popd &> /dev/null | ||
} | ||
|
||
# Runs all the unit tests. | ||
function looker::test() { | ||
pushd "$GIT_ROOT_DIR" &> /dev/null | ||
env NODE_OPTIONS="--openssl-legacy-provider" yarn test | ||
popd &> /dev/null | ||
} | ||
|
||
# Entry-point. | ||
function looker::main() { | ||
looker::configure | ||
looker::test | ||
} | ||
|
||
looker::main | ||
|
||
exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
/** Regular expression for the special characters that are trimmed by | ||
* default from a string. */ | ||
const LEADING_TRAILING_SPECIAL_CHARS_REGEX = | ||
/(^| +)[!-\/:-@\[-`\{-~]*([^ ]*?)[!-\/:-@\[-`\{-~]*(?=\s|$)/gi; | ||
|
||
/** | ||
* Trims leading and trailing special characters from the string. | ||
* | ||
* @param {string} str The string to trim. | ||
* @param {RegExp} pattern The pattern representing the special charaters. | ||
* @return {string} The sanitized string. | ||
*/ | ||
export function trimSpecialCharacters( | ||
str, | ||
pattern = LEADING_TRAILING_SPECIAL_CHARS_REGEX | ||
) { | ||
return str.replace(pattern, '$1$2'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import {trimSpecialCharacters} from './string'; | ||
|
||
describe('trimSpecialCharacters', () => { | ||
test('should trim leading special characters', () => { | ||
expect(trimSpecialCharacters('$$_aa')).toBe('aa'); | ||
}); | ||
test('should trim trailing special characters', () => { | ||
expect(trimSpecialCharacters('aa_$$')).toBe('aa'); | ||
}); | ||
test('should trim both leading and trailing special characters', () => { | ||
expect(trimSpecialCharacters('$$_aa_$$')).toBe('aa'); | ||
}); | ||
test('should leave empty string alone', () => { | ||
expect(trimSpecialCharacters('')).toBe(''); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.