diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..3db2cbc --- /dev/null +++ b/.devcontainer/Dockerfile @@ -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 \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..7bfe7a6 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -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" + } + } + } +} \ No newline at end of file diff --git a/.devcontainer/docker-compose.yml b/.devcontainer/docker-compose.yml new file mode 100644 index 0000000..3a68f93 --- /dev/null +++ b/.devcontainer/docker-compose.yml @@ -0,0 +1,11 @@ +version: '3.9' + +services: + + switcherclientjs: + build: + context: . + dockerfile: Dockerfile + volumes: + - ..:/workspace:cached + command: sleep infinity \ No newline at end of file diff --git a/.env.template b/.env.template new file mode 100644 index 0000000..c096a13 --- /dev/null +++ b/.env.template @@ -0,0 +1,2 @@ +# Create .env file for local Development and Integration Testing +SWITCHER_API_KEY="[SWITCHER_API_KEY]" \ No newline at end of file diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml index a3de7cb..d9a5472 100644 --- a/.github/workflows/master.yml +++ b/.github/workflows/master.yml @@ -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 }} diff --git a/package.json b/package.json index 105ebf2..b5d2271 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/test/playground/index.js b/test/playground/index.js index ba5d9ac..cead18e 100644 --- a/test/playground/index.js +++ b/test/playground/index.js @@ -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/'; diff --git a/test/switcher-integrated.test.js b/test/switcher-integrated.test.js index 367fea6..aa3c90b 100644 --- a/test/switcher-integrated.test.js +++ b/test/switcher-integrated.test.js @@ -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); }); diff --git a/test/switcher-snapshot.test.js b/test/switcher-snapshot.test.js index e145d24..6b059da 100644 --- a/test/switcher-snapshot.test.js +++ b/test/switcher-snapshot.test.js @@ -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'; @@ -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() { @@ -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() { @@ -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(); });