Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#-------------------------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
#-------------------------------------------------------------------------------------------------------------
FROM node:22

# The node image includes a non-root user with sudo access. Use the
# "remoteUser" property in devcontainer.json to use it. On Linux, update
# these values to ensure the container user's UID/GID matches your local values.
# See https://aka.ms/vscode-remote/containers/non-root-user for details.
ARG USERNAME=node
ARG USER_UID=1000
ARG USER_GID=$USER_UID

RUN echo "deb http://archive.debian.org/debian stretch main" > /etc/apt/sources.list

# Configure apt and install packages
RUN apt-get update \
&& apt-get -y install --no-install-recommends dialog 2>&1 \
# Verify git and needed tools are installed
&& apt-get -y install git iproute2 procps \
# Update npm to the latest version
&& npm install -g npm@latest \
# Clean up
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# set up a nicer prompt
RUN git clone https://github.com/magicmonty/bash-git-prompt.git ~/.bash-git-prompt --depth=1

RUN echo "source $HOME/.bash-git-prompt/gitprompt.sh" >> ~/.bashrc
16 changes: 16 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "Switcher Client JS Dev Container",
"dockerComposeFile": [
"docker-compose.yml"
],
"service": "switcherclientjs",
"workspaceFolder": "/workspace",
"customizations":{
"vscode": {
"extensions": ["dbaeumer.vscode-eslint"],
"settings": {
"terminal.integrated.shell.linux": "/bin/bash"
}
}
}
}
11 changes: 11 additions & 0 deletions .devcontainer/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: '3.9'

services:

switcherclientjs:
build:
context: .
dockerfile: Dockerfile
volumes:
- ..:/workspace:cached
command: sleep infinity
2 changes: 2 additions & 0 deletions .env.template
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Create .env file for local Development and Integration Testing
SWITCHER_API_KEY="[SWITCHER_API_KEY]"
2 changes: 1 addition & 1 deletion .github/workflows/master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
SWITCHER_API_KEY: ${{ secrets.SWITCHER_API_KEY }}

- name: SonarCloud Scan
uses: sonarsource/sonarqube-scan-action@v5.0.0
uses: sonarsource/sonarqube-scan-action@v5.1.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
"src/"
],
"devDependencies": {
"@babel/eslint-parser": "^7.26.8",
"@typescript-eslint/eslint-plugin": "^8.26.0",
"@typescript-eslint/parser": "^8.26.0",
"@babel/eslint-parser": "^7.27.0",
"@typescript-eslint/eslint-plugin": "^8.31.0",
"@typescript-eslint/parser": "^8.31.0",
"c8": "^10.1.3",
"chai": "^5.2.0",
"env-cmd": "^10.1.0",
"eslint": "^9.22.0",
"eslint": "^9.25.1",
"mocha": "^11.1.0",
"mocha-sonarqube-reporter": "^1.0.2",
"sinon": "^19.0.2"
"sinon": "^20.0.0"
},
"repository": {
"type": "git",
Expand Down
6 changes: 3 additions & 3 deletions test/playground/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Client } from '../../switcher-client.js';
import { sleep } from '../helper/utils.js';

const SWITCHER_KEY = 'MY_SWITCHER';
const SWITCHER_KEY = 'CLIENT_JS_FEATURE';
const apiKey = process.env.SWITCHER_API_KEY;
const domain = 'Playground';
const component = 'switcher-playground';
const domain = 'Switcher API';
const component = 'switcher-client-js';
const environment = 'default';
const url = 'https://api.switcherapi.com';
const snapshotLocation = './test/playground/snapshot/';
Expand Down
6 changes: 3 additions & 3 deletions test/switcher-integrated.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ describe('Switcher integrated test', () => {
Client.buildContext({
url: 'https://api.switcherapi.com',
apiKey: process.env.SWITCHER_API_KEY,
domain: 'Playground',
component: 'switcher-playground'
domain: 'Switcher API',
component: 'switcher-client-js'
});

// test
const switcher = Client.getSwitcher().detail();
const result = await switcher.isItOn('CLIENT_JS_FEATURE_1');
const result = await switcher.isItOn('CLIENT_JS_FEATURE');

assert.isNotNull(result);
});
Expand Down
31 changes: 10 additions & 21 deletions test/switcher-snapshot.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@ import { Client } from '../switcher-client.js';
import FetchFacade from '../src/lib/utils/fetchFacade.js';
import { given, givenError, generateAuth, generateStatus, assertReject, assertResolve, sleep, deleteGeneratedSnapshot } from './helper/utils.js';

const restoreStub = (fetchStub) => {
if (fetchStub) {
fetchStub.restore();
}
}

describe('E2E test - Switcher local - Snapshot:', function () {
const apiKey = '[api_key]';
const domain = 'Business';
Expand All @@ -17,14 +23,9 @@ describe('E2E test - Switcher local - Snapshot:', function () {
const dataJSON = dataBuffer.toString();

let fetchStub;
let fsStub;

afterEach(function() {
if (fetchStub != undefined)
fetchStub.restore();

if (fsStub != undefined)
fsStub.restore();
restoreStub(fetchStub);
});

beforeEach(function() {
Expand Down Expand Up @@ -216,14 +217,9 @@ describe('E2E test - Fail response - Snapshot:', function () {
const url = 'http://localhost:3000';

let fetchStub;
let fsStub;

afterEach(function() {
if (fetchStub != undefined)
fetchStub.restore();

if (fsStub != undefined)
fsStub.restore();
restoreStub(fetchStub);
});

beforeEach(function() {
Expand Down Expand Up @@ -285,20 +281,13 @@ describe('E2E test - Snapshot AutoUpdater:', function () {
const dataJSONV2 = dataBufferV2.toString();

let fetchStub;
let fsStub;

afterEach(function() {
if (fetchStub != undefined)
fetchStub.restore();

if (fsStub != undefined)
fsStub.restore();
restoreStub(fetchStub);
});

beforeEach(function() {
Client.buildContext({ url, apiKey, domain, component, environment }, {
local: true
});
Client.buildContext({ url, apiKey, domain, component, environment }, { local: true });
Client.testMode();
});

Expand Down