Skip to content

Commit

Permalink
Allow fixture to start with leading /
Browse files Browse the repository at this point in the history
  • Loading branch information
lettertwo committed Jul 12, 2023
1 parent 58af4a1 commit cc6c1d8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 4 deletions.
6 changes: 6 additions & 0 deletions packages/core/test-utils/src/fsFixture.js
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ export class FixtureParser {
this.#cwd = this.#root;
this.#dirStack = [this.#root];

// Consume any leading `nest` tokens.
// This allows a fixture path to start with '/'.
while (this.#peek('nest')) {
this.#consume('nest');
}

while (this.#tokens.length) {
this.#parseNest();
if (this.#peek('dirname')) {
Expand Down
34 changes: 30 additions & 4 deletions packages/core/test-utils/test/fsFixture.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,10 +241,7 @@ describe('FixtureParser', () => {
});

it('errors on invalid nesting', () => {
let result = new FixtureParser([{type: 'nest', value: ''}]);
assert.throws(() => result.parse(), /Invalid nesting/);

result = new FixtureParser([
let result = new FixtureParser([
{type: 'filename', value: 'foo'},
{type: 'content', value: ''},
{type: 'nest', value: ''},
Expand Down Expand Up @@ -431,6 +428,35 @@ describe('FixtureParser', () => {

assert.deepEqual(result, expected);
});

it('parses a leading /', () => {
// /foo
// bar
// /bat
// /baz/qux
let result = new FixtureParser([
{type: 'nest', value: '/'},
{type: 'dirname', value: 'foo'},
{type: 'nest', value: ''},
{type: 'dirname', value: 'bar'},
{type: 'nest', value: '/'},
{type: 'dirname', value: 'bat'},
{type: 'nest', value: '/'},
{type: 'dirname', value: 'baz'},
{type: 'nest', value: '/'},
{type: 'dirname', value: 'qux'},
]).parse();

let expected = new FixtureRoot();
let foo, bar, bat, baz;
expected.children.push((foo = new FixtureDir('foo')));
foo.children.push((bar = new FixtureDir('bar')));
bar.children.push((bat = new FixtureDir('bat')));
bat.children.push((baz = new FixtureDir('baz')));
baz.children.push(new FixtureDir('qux'));

assert.deepEqual(result, expected);
});
});

describe('fsFixture', () => {
Expand Down

0 comments on commit cc6c1d8

Please sign in to comment.