microsoft/vscode-react-native
Publicmirrored from https://github.com/microsoft/vscode-react-nativeAvailable
test/common/utils.test.ts
82lines · modecode
| 1 | // Copyright (c) Microsoft Corporation. All rights reserved. |
| 2 | // Licensed under the MIT license. See LICENSE file in the project root for details. |
| 3 | import assert = require("assert"); |
| 4 | import { stripJsonTrailingComma } from "../../src/common/utils"; |
| 5 | |
| 6 | suite("utilHelper", function () { |
| 7 | suite("stripJsonTrailingComma", function () { |
| 8 | test("should remove trailing comma from a JSON", (done: Mocha.Done) => { |
| 9 | const strWithTrailingComma = ` |
| 10 | { |
| 11 | "runtimeArgs": [ |
| 12 | "--inspect-brk=9237", |
| 13 | "start", |
| 14 | ], |
| 15 | "runtimeVersion": "12.16.3", |
| 16 | "port": 9237, |
| 17 | "type": "node", |
| 18 | "name": "some-project", |
| 19 | "timeout": 300000 |
| 20 | } |
| 21 | `; |
| 22 | const strObject = stripJsonTrailingComma(strWithTrailingComma); |
| 23 | const strippedStr = `{ |
| 24 | "runtimeArgs": [ |
| 25 | "--inspect-brk=9237", |
| 26 | "start" |
| 27 | ], |
| 28 | "runtimeVersion": "12.16.3", |
| 29 | "port": 9237, |
| 30 | "type": "node", |
| 31 | "name": "some-project", |
| 32 | "timeout": 300000 |
| 33 | }`; |
| 34 | const strippedStrObject = JSON.parse(strippedStr); |
| 35 | assert.strictEqual(JSON.stringify(strObject), JSON.stringify(strippedStrObject)); |
| 36 | done(); |
| 37 | }); |
| 38 | |
| 39 | test("should manage string contains end of string trailing comma", (done: Mocha.Done) => { |
| 40 | const strWithTrailingComma = ` |
| 41 | { |
| 42 | "version": "0.2.0", |
| 43 | "configurations": [ |
| 44 | { |
| 45 | "name": "Debug Android", |
| 46 | "cwd": "\${workspaceFolder\}", |
| 47 | "type": "reactnative", |
| 48 | "request": "launch", |
| 49 | "platform": "android", |
| 50 | "logCatArguments": ["ReactNative", "ReactNativeJS"], |
| 51 | "env": { |
| 52 | "testvar": "(value0), (value1), (value2)" |
| 53 | } |
| 54 | } |
| 55 | ] |
| 56 | }, |
| 57 | `; |
| 58 | const strObject = stripJsonTrailingComma(strWithTrailingComma); |
| 59 | const strippedStr = ` |
| 60 | { |
| 61 | "version": "0.2.0", |
| 62 | "configurations": [ |
| 63 | { |
| 64 | "name": "Debug Android", |
| 65 | "cwd": "\${workspaceFolder\}", |
| 66 | "type": "reactnative", |
| 67 | "request": "launch", |
| 68 | "platform": "android", |
| 69 | "logCatArguments": ["ReactNative", "ReactNativeJS"], |
| 70 | "env": { |
| 71 | "testvar": "(value0), (value1), (value2)" |
| 72 | } |
| 73 | } |
| 74 | ] |
| 75 | } |
| 76 | `; |
| 77 | const strippedStrObject = JSON.parse(strippedStr); |
| 78 | assert.strictEqual(JSON.stringify(strObject), JSON.stringify(strippedStrObject)); |
| 79 | done(); |
| 80 | }); |
| 81 | }); |
| 82 | }); |
| 83 | |