refactor: improve feature string parsing (#23130)

* test: add pre-change snapshot of new-window event

* move to .ts file for easier diff

* refactor: improve feature string parsing logic

* test: update snapshots

* update type names per review

* update comma-separated parse test

* use for loop instead of reduce per review

* tighten up types

* avoid variable guest contents id returnValue in test snapshot
This commit is contained in:
loc 2020-04-21 13:23:00 -07:00 committed by GitHub
parent b3909f5600
commit aca2e4f968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 589 additions and 108 deletions

View file

@ -2,10 +2,9 @@ import { expect } from 'chai';
describe('feature-string parsing', () => {
it('is indifferent to whitespace around keys and values', () => {
const { parseFeaturesString } = require('../lib/common/parse-features-string');
const { parseCommaSeparatedKeyValue } = require('../lib/common/parse-features-string');
const checkParse = (string: string, parsed: Record<string, string | boolean>) => {
const features: Record<string, string | boolean> = {};
parseFeaturesString(string, (k: string, v: any) => { features[k] = v; });
const features = parseCommaSeparatedKeyValue(string, true).parsed;
expect(features).to.deep.equal(parsed);
};
checkParse('a=yes,c=d', { a: true, c: 'd' });