Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
peschee committed Oct 5, 2023
1 parent b3de16a commit 78ccfc0
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions test/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -303,3 +303,40 @@ test('replacements with window[] trimming (case insensitive)', async t => {
t.deepEqual(replacements, replacementsShould);
}
});

test('can use spaces in default values', async t => {
const defaultValue = 'foo bar';
let [replaced, replacements] = await replaceVariables(`\${VAR:-${defaultValue}}`);
t.is(replaced, defaultValue);
t.deepEqual(replacements, [{ from: `\${VAR:-${defaultValue}}`, to: defaultValue, count: 1 }]);
});

test('can use spaces in default values (prefix)', async t => {
const defaultValue = 'foo bar';
const [replaced, replacements] = await replaceVariables(`\${PREFIX_VAR:-${defaultValue}}`, {}, 'PREFIX_');
t.is(replaced, defaultValue);
t.deepEqual(replacements, [{ from: `\${PREFIX_VAR:-${defaultValue}}`, to: defaultValue, count: 1 }]);
});

test('can use spaces in default values (window)', async t => {
const defaultValue = 'foo bar';
const [replaced, replacements] = await replaceVariables(`window["$\{VAR:-${defaultValue}}"]`, {}, '', true);
t.is(replaced, `"${defaultValue}"`);
t.deepEqual(replacements, [{ from: `window["$\{VAR:-${defaultValue}}"]`, to: `"${defaultValue}"`, count: 1 }]);
});

test('can replace variable placeholders that have spaces in default values', async t => {
const defaultValue = 'foo bar';
const variable = 'bar baz';
const [replaced, replacements] = await replaceVariables(`\${VAR:-${defaultValue}}`, { VAR: variable });
t.is(replaced, variable);
t.deepEqual(replacements, [{ from: `\${VAR:-${defaultValue}}`, to: variable, count: 1 }]);
});

test('can replace variable placeholders that have spaces in default values (prefix)', async t => {
const defaultValue = 'foo bar';
const variable = 'bar baz';
const [replaced, replacements] = await replaceVariables(`\${PREFIX_VAR:-${defaultValue}}`, { PREFIX_VAR: variable }, 'PREFIX_');
t.is(replaced, variable);
t.deepEqual(replacements, [{ from: `\${PREFIX_VAR:-${defaultValue}}`, to: variable, count: 1 }]);
});

0 comments on commit 78ccfc0

Please sign in to comment.