Skip to content

Commit

Permalink
[steps] Add tests
Browse files Browse the repository at this point in the history
Added tests for global fix for new line escape characters

See: expo/eas-cli#2261
  • Loading branch information
radoslawkrzemien committed Mar 11, 2024
1 parent 9991c00 commit edc9fd5
Showing 1 changed file with 96 additions and 0 deletions.
96 changes: 96 additions & 0 deletions packages/steps/src/__tests__/BuildStepInput-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,42 @@ describe(BuildStepInput, () => {
expect(i.value).toEqual('linux');
});

test('context value string with newline characters', () => {
const ctx = createGlobalContextMock({
staticContextContent: {
foo: {
bar: 'Line 1\nLine 2\n\nLine 3',
},
} as unknown as BuildStaticContext,
});
const i = new BuildStepInput(ctx, {
id: 'foo',
stepDisplayName: BuildStep.getDisplayName({ id: 'test1' }),
defaultValue: '${ eas.foo.bar }',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
});
expect(i.value).toEqual('Line 1\nLine 2\n\nLine 3');
});

test('context value string with doubly escaped newline characters', () => {
const ctx = createGlobalContextMock({
staticContextContent: {
foo: {
bar: 'Line 1\\nLine 2\\n\\nLine 3',
},
} as unknown as BuildStaticContext,
});
const i = new BuildStepInput(ctx, {
id: 'foo',
stepDisplayName: BuildStep.getDisplayName({ id: 'test1' }),
defaultValue: '${ eas.foo.bar }',
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.STRING,
});
expect(i.value).toEqual('Line 1\nLine 2\n\nLine 3');
});

test('context value number', () => {
const ctx = createGlobalContextMock({
staticContextContent: {
Expand Down Expand Up @@ -321,6 +357,66 @@ describe(BuildStepInput, () => {
});
});

test('context values in an object with newline characters', () => {
const ctx = createGlobalContextMock({
staticContextContent: {
context_val_1: 'Line 1\nLine 2\n\nLine 3',
} as unknown as BuildStaticContext,
});
const i = new BuildStepInput(ctx, {
id: 'foo',
stepDisplayName: BuildStep.getDisplayName({ id: 'test1' }),
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.JSON,
});
i.set({
foo: 'foo',
bar: '${ eas.context_val_1 }',
baz: {
bazfoo: 'bazfoo',
bazbaz: ['bazbaz', '${ eas.context_val_1 }'],
},
});
expect(i.value).toEqual({
foo: 'foo',
bar: 'Line 1\nLine 2\n\nLine 3',
baz: {
bazfoo: 'bazfoo',
bazbaz: ['bazbaz', 'Line 1\nLine 2\n\nLine 3'],
},
});
});

test('context values in an object with doubly escaped newline characters', () => {
const ctx = createGlobalContextMock({
staticContextContent: {
context_val_1: 'Line 1\\nLine 2\\n\\nLine 3',
} as unknown as BuildStaticContext,
});
const i = new BuildStepInput(ctx, {
id: 'foo',
stepDisplayName: BuildStep.getDisplayName({ id: 'test1' }),
required: true,
allowedValueTypeName: BuildStepInputValueTypeName.JSON,
});
i.set({
foo: 'foo',
bar: '${ eas.context_val_1 }',
baz: {
bazfoo: 'bazfoo',
bazbaz: ['bazbaz', '${ eas.context_val_1 }'],
},
});
expect(i.value).toEqual({
foo: 'foo',
bar: 'Line 1\nLine 2\n\nLine 3',
baz: {
bazfoo: 'bazfoo',
bazbaz: ['bazbaz', 'Line 1\nLine 2\n\nLine 3'],
},
});
});

test('default value number', () => {
const ctx = createGlobalContextMock();
const i = new BuildStepInput(ctx, {
Expand Down

0 comments on commit edc9fd5

Please sign in to comment.