Skip to content

Commit

Permalink
feat: add additional tests (#10)
Browse files Browse the repository at this point in the history
chore(bootstrap): add pnpm installation

fix: ensure bootstrap works on distros with apt as the package manager

feat: use pnpm to build our binaries

fix: Failing unit tests

fix: Updated build
  • Loading branch information
andres-rubio-go authored Oct 5, 2023
1 parent 255969e commit 4f23b8c
Show file tree
Hide file tree
Showing 13 changed files with 972 additions and 881 deletions.
9 changes: 8 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ repos:
- id: mixed-line-ending
args: [--fix, lf]
- repo: https://github.com/pre-commit/mirrors-prettier
rev: 'v3.0.0-alpha.9-for-vscode'
rev: 'v3.0.3'
hooks:
- id: prettier
- repo: local
hooks:
- id: unit-tests-suite
name: unit-tests-suite
description: Runs test suites
entry: bin/test
language: script
2 changes: 1 addition & 1 deletion bargauge.js

Large diffs are not rendered by default.

16 changes: 10 additions & 6 deletions bin/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,22 @@ GIT_ROOT_DIR=$(git rev-parse --show-toplevel)

# Initialize and install pre-commit.
function looker::install_pre_commit() {
pushd "$GIT_ROOT_DIR" &> /dev/null
if command -v pre-commit &> /dev/null; then
python3 -m pip install --upgrade pip
python3 -m pip install pre-commit
pushd "$GIT_ROOT_DIR" &>/dev/null
if ! command -v pre-commit &>/dev/null; then
if command -v apt &>/dev/null; then
sudo apt install -y pre-commit
else
python3 -m pip install --upgrade pip
python3 -m pip install pre-commit
fi
fi
pre-commit install
popd &> /dev/null
popd &>/dev/null
}

# Installs yarn if it is not already installed.
function looker::install_yarn() {
if command -v yarn &> /dev/null; then
if ! command -v yarn &>/dev/null; then
npm install -g yarn
fi
}
Expand Down
12 changes: 6 additions & 6 deletions bin/build
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ 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
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
pushd "$GIT_ROOT_DIR" &>/dev/null
if [[ ! -d "$GIT_ROOT_DIR/node_modules" ]]; then
yarn
fi
popd &> /dev/null
popd &>/dev/null
}

# Builds the target JS file from sources configuring if necessary.
function looker::build() {
pushd "$GIT_ROOT_DIR" &> /dev/null
env NODE_OPTIONS="--openssl-legacy-provider" yarn build
popd &> /dev/null
pushd "$GIT_ROOT_DIR" &>/dev/null
env NODE_OPTIONS="--openssl-legacy-provider" yarn run build
popd &>/dev/null
}

# Entry-point.
Expand Down
10 changes: 5 additions & 5 deletions bin/test
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@ 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
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
pushd "$GIT_ROOT_DIR" &>/dev/null
if [[ ! -d "$GIT_ROOT_DIR/node_modules" ]]; then
yarn
fi
popd &> /dev/null
popd &>/dev/null
}

# Runs all the unit tests.
function looker::test() {
pushd "$GIT_ROOT_DIR" &> /dev/null
pushd "$GIT_ROOT_DIR" &>/dev/null
env NODE_OPTIONS="--openssl-legacy-provider" yarn test
popd &> /dev/null
popd &>/dev/null
}

# Entry-point.
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
"description": "",
"main": "",
"scripts": {
"build": "webpack --config webpack.config.js",
"prepare": "bin/bootstrap",
"build": "env NODE_OPTIONS='--openssl-legacy-provider' webpack --config webpack.config.js",
"start": "webpack-dev-server --open",
"watch": "webpack --config webpack.config.js --watch --progress",
"format": "prettier --ignore-path .gitignore --write '**/*.js'",
"watch": "env NODE_OPTIONS='--openssl-legacy-provider' webpack --config webpack.config.js --watch --progress",
"format": "prettier --ignore-path .gitignore --write src",
"test": "jest"
},
"author": "Apps Team <marketplace@looker.com>",
Expand Down
21 changes: 9 additions & 12 deletions src/helpers.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import SSF from 'ssf';

export function processData(data, queryResponse, config, viz) {
let dims, dimID, dimData;
let meas, mesID, mesData, mesLabel, mesRendered;
const dims = queryResponse['fields']['dimension_like'];
const meas = queryResponse['fields']['measure_like'];

let dimID, dimData;
let mesID, mesData, mesLabel, mesRendered;
let tarID, tarData, tarValue, tarLabel, tarBase, tarRendered, tarDim;
dims = queryResponse['fields']['dimension_like'];
meas = queryResponse['fields']['measure_like'];

if (dims.length > 0) {
dimID = dims[0]['name'];
Expand Down Expand Up @@ -56,8 +57,7 @@ export function processData(data, queryResponse, config, viz) {
meas[1]['label_short'] === undefined
? meas[1]['label']
: meas[1]['label_short'];
tarBase =
tarData.rendered === undefined ? tarData.value : tarData.rendered;
tarBase = tarData.rendered === undefined ? tarData.value : tarData.rendered;
tarRendered =
config.bar_target_value_format === undefined ||
config.bar_target_value_format === ''
Expand Down Expand Up @@ -99,8 +99,7 @@ export function processData(data, queryResponse, config, viz) {
} else if (config.bar_target_source === 'override') {
if (
config.bar_target_value_override === undefined ||
config.bar_target_value_override === '' &&
viz
(config.bar_target_value_override === '' && viz)
) {
viz.addError({
title: 'Invalid Input.',
Expand Down Expand Up @@ -153,7 +152,7 @@ export function processData(data, queryResponse, config, viz) {
config.bar_target_label_override === ''
? tarLabel
: config.bar_target_label_override,
target_dimension: tarDim
target_dimension: tarDim,
};
return chunk;
}
Expand All @@ -174,9 +173,7 @@ export function getBarDefaults(width, height, margin, config, chunk) {
chunk.value > config.bar_range_max ? config.bar_range_max : chunk.value,
value_rendered: chunk.value_rendered,
target:
chunk.target > config.bar_range_max
? config.bar_range_max
: chunk.target,
chunk.target > config.bar_range_max ? config.bar_range_max : chunk.target,
value_label: chunk.value_label,
target_label: chunk.target_label,
value_dimension: chunk.value_dimension,
Expand Down
Loading

0 comments on commit 4f23b8c

Please sign in to comment.