@jest/globals#it TypeScript Examples
The following examples show how to use
@jest/globals#it.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: github.test.ts From setup-buildx-action with Apache License 2.0 | 6 votes |
describe('github', () => {
it('returns latest buildx GitHub release', async () => {
const release = await github.getRelease('latest');
expect(release).not.toBeNull();
expect(release?.tag_name).not.toEqual('');
});
it('returns v0.2.2 buildx GitHub release', async () => {
const release = await github.getRelease('v0.2.2');
expect(release).not.toBeNull();
expect(release?.tag_name).toEqual('v0.2.2');
});
});
Example #2
Source File: utils.spec.ts From ya-webadb with MIT License | 6 votes |
describe('placeholder', () => {
it('should return `undefined`', () => {
expect(placeholder()).toBe(undefined);
});
});
Example #3
Source File: PluginSimpleStack.test.tsx From ui-schema with MIT License | 6 votes |
describe('PluginSimpleStack', () => {
it('PluginSimpleStack', async () => {
const {queryByText} = render(
// ts-@ignore
<PluginSimpleStack
// ts-@ignore
handled
// ts-@ignore
widgets={{
WidgetRenderer: WidgetRenderer,
types: {
// @ts-ignore
string: ({valid, handled}: { valid?: boolean, handled?: boolean }) =>
valid === true && handled === true ? 'is-valid' : 'is-invalid',
},
pluginSimpleStack: [{handle: () => ({valid: true})}],
pluginStack: [],
}}
schema={createOrderedMap({type: 'string'})}
/>
)
expect(queryByText('is-valid') !== null).toBeTruthy()
})
})
Example #4
Source File: adsense.spec.tsx From react-adsense with MIT License | 6 votes |
describe('Adsense', () => {
it('should be instantiable', () => {
const { container } = render(<Adsense client="123" slot="abc" className="ads-class" />);
expect(container.firstChild).toMatchSnapshot();
});
it('should call window adsbygoogle', () => {
(window as any).adsbygoogle = [];
render(<Adsense client="123" slot="abc" />);
expect((window as any).adsbygoogle).toHaveLength(1);
(window as any).adsbygoogle = undefined;
});
});
Example #5
Source File: tree-clusters.spec.ts From flame-chart-js with MIT License | 6 votes |
describe('tree clusters', () => {
it('flatTree', () => {
expect(flatTree(data)).toStrictEqual(flatTreeData);
});
it('metaClusterizeFlatTree', () => {
expect(metaClusterizeFlatTree(flatTreeData)).toStrictEqual(metaClusterizedFlatTree);
});
it('clusterizeFlatTree', () => {
const result = clusterizeFlatTree(metaClusterizedFlatTree, 1, 0, 500);
expect(result).toStrictEqual(clusterizedFlatTree);
});
it('reclusterizeClusteredFlatTree', () => {
const result = reclusterizeClusteredFlatTree(clusterizedFlatTree, 1, 0, 500);
expect(result).toStrictEqual(reclusterizedClusteredFlatTree);
expect(clusterizedFlatTree).toStrictEqual(reclusterizedClusteredFlatTree);
});
});
Example #6
Source File: githubstatus.test.ts From ghaction-github-status with MIT License | 6 votes |
describe('githubstatus', () => {
it('returns GitHub Status (status)', async () => {
const status = await githubstatus.status();
expect(status?.indicator).not.toEqual('');
});
it('returns GitHub Status (summary)', async () => {
const summary = await githubstatus.summary();
expect(summary?.status.indicator).not.toEqual('');
expect(summary?.components?.length).toBeGreaterThan(0);
});
});
Example #7
Source File: context.test.ts From setup-buildx-action with Apache License 2.0 | 6 votes |
describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn() as typeof process.stdout.write;
});
// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
});
});
Example #8
Source File: context.test.ts From build-push-action with Apache License 2.0 | 6 votes |
describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn() as typeof process.stdout.write;
});
// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
});
});
Example #9
Source File: context.test.ts From ghaction-virustotal with MIT License | 6 votes |
describe('setOutput', () => {
beforeEach(() => {
process.stdout.write = jest.fn() as typeof process.stdout.write;
});
// eslint-disable-next-line jest/expect-expect
it('setOutput produces the correct command', () => {
context.setOutput('some output', 'some value');
assertWriteCalls([`::set-output name=some output::some value${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles bools', () => {
context.setOutput('some output', false);
assertWriteCalls([`::set-output name=some output::false${os.EOL}`]);
});
// eslint-disable-next-line jest/expect-expect
it('setOutput handles numbers', () => {
context.setOutput('some output', 1.01);
assertWriteCalls([`::set-output name=some output::1.01${os.EOL}`]);
});
});
Example #10
Source File: util.test.ts From ghaction-github-status with MIT License | 6 votes |
describe('util', () => {
it('returns github status components', async () => {
const summary = await githubstatus.summary();
await util.asyncForEach(summary?.components, async component => {
expect(component?.name).not.toEqual('');
});
});
});
Example #11
Source File: context.test.ts From ghaction-virustotal with MIT License | 6 votes |
describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar']);
});
it('handles multiple lines correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});
});
Example #12
Source File: context.test.ts From bake-action with Apache License 2.0 | 6 votes |
describe('asyncForEach', () => {
it('executes async tasks sequentially', async () => {
const testValues = [1, 2, 3, 4, 5];
const results: number[] = [];
await context.asyncForEach(testValues, async value => {
results.push(value);
});
expect(results).toEqual(testValues);
});
});
Example #13
Source File: context.test.ts From setup-buildx-action with Apache License 2.0 | 5 votes |
describe('getInputList', () => {
it('handles single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar']);
});
it('handles multiple lines correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('remove empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('remove empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('handles different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});
it('handles multiple lines and ignoring comma correctly', async () => {
setInput('driver-opts', 'image=moby/buildkit:master\nnetwork=host');
const res = await context.getInputList('driver-opts', true);
expect(res).toEqual(['image=moby/buildkit:master', 'network=host']);
});
it('handles different new lines and ignoring comma correctly', async () => {
setInput('driver-opts', 'image=moby/buildkit:master\r\nnetwork=host');
const res = await context.getInputList('driver-opts', true);
expect(res).toEqual(['image=moby/buildkit:master', 'network=host']);
});
});
Example #14
Source File: buildx.test.ts From build-push-action with Apache License 2.0 | 5 votes |
describe('getDigest', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getDigest(metadata);
expect(expected).toEqual('sha256:b09b9482c72371486bb2c1d2c2a2633ed1d0b8389e12c8d52b9e052725c0c83c');
});
});
Example #15
Source File: index.spec.ts From ya-webadb with MIT License | 5 votes |
describe('Struct', () => {
describe("Index", () => {
it('should export default Struct', () => {
expect(Struct).toBeDefined();
});
});
});
Example #16
Source File: context.test.ts From ghaction-virustotal with MIT License | 5 votes |
describe('resolvePaths', () => {
it('resolves files given a set of paths', async () => {
expect(context.resolvePaths(['tests/data/**/*'])).toEqual(['tests/data/foo/bar.txt']);
});
});
Example #17
Source File: index.spec.ts From ya-webadb with MIT License | 5 votes |
describe('BTree', () => {
describe('insert', () => {
function validate(log: any[], min = -Infinity) {
for (const item of log) {
if (Array.isArray(item)) {
min = validate(item, min);
} else if (typeof item === 'number') {
if (item < min) {
throw new Error();
}
min = item;
}
}
return min;
}
it('should work with incremental values', () => {
const tree = new BTree(6);
const values = Array.from({ length: 1024 }, (_, i) => i);
for (let i = 0; i < values.length; i += 1) {
tree.insert(values[i]!);
expect(() => validate(tree.root.log())).not.toThrow();
}
});
it('should work with random data', () => {
const tree = new BTree(6);
const values = Array.from({ length: 1024 }, () => Math.random() * 1024 | 0);
// const values = Array.from({ length: 1024 }, (_, i) => 1024 - i);
// const values = Array.from({ length: 1024 }, (_, i) => i);
for (let i = 0; i < values.length; i += 1) {
tree.insert(values[i]!);
expect(() => validate(tree.root.log())).not.toThrow();
}
});
});
describe('has', () => {
it('should return true for inserted values', () => {
const tree = new BTree(6);
const values = Array.from({ length: 1024 }, () => Math.random() * 512 + 512 | 0);
for (const value of values) {
tree.insert(value);
}
for (let i = -1024; i < 2048; i++) {
expect(tree.has(i)).toBe(values.includes(i));
}
});
});
});
Example #18
Source File: UIRenderer.test.tsx From ui-schema with MIT License | 5 votes |
describe('UIGenerator Integration', () => {
it('TestUIRenderer', async () => {
const {queryByText, queryAllByText, container} = render(
<TestUIRenderer data={{demo_number: 10, demo_array2: ['val-test']}}/>
)
expect(container.querySelectorAll('.root-renderer').length).toBe(1)
expect(container.querySelectorAll('.group-renderer').length).toBe(2)
expect(queryByText('store-is-correct') !== null).toBeTruthy()
expect(queryByText('store-is-invalid')).toBe(null)
expect(queryByText('widget.demo_string.title') !== null).toBeTruthy()
expect(queryAllByText('string-renderer').length).toBe(4)
expect(queryByText('string-with-error') === null).toBeTruthy()
expect(queryByText('missing-type-number') !== null).toBeTruthy()
expect(queryAllByText('array-renderer').length).toBe(3)
})
it('TestUIRenderer no `store`', async () => {
const {queryByText, queryAllByText, container} = render(
<TestUIRenderer noStore/>
)
// expect(container).toMatchSnapshot()
expect(container.querySelectorAll('.root-renderer').length).toBe(1)
expect(container.querySelectorAll('.group-renderer').length).toBe(2)
expect(queryByText('Demo String')).toBe(null)
expect(queryByText('widget.demo_string.title') !== null).toBeTruthy()
expect(queryAllByText('string-renderer').length).toBe(2)
expect(queryByText('store-is-invalid') !== null).toBeTruthy()
})
it('TestUIRenderer not `t`', async () => {
const {queryByText, queryAllByText, container} = render(
<TestUIRenderer notT/>
)
expect(container.querySelectorAll('.root-renderer').length).toBe(1)
expect(container.querySelectorAll('.group-renderer').length).toBe(2)
expect(queryByText('Demo String') !== null).toBeTruthy()
expect(queryByText('widget.demo_string.title')).toBe(null)
expect(queryAllByText('string-renderer').length).toBe(3)
})
it('TestUIRenderer ConditionalCombining', async () => {
const {queryByText, container} = render(
<TestUIRenderer data={{demo_string: 'test'}}/>
)
// expect(container).toMatchSnapshot()
expect(container.querySelectorAll('.root-renderer').length === 1).toBeTruthy()
expect(container.querySelectorAll('.group-renderer').length > 0).toBeTruthy()
expect(queryByText('widget.demo_string.title') == null).toBeTruthy()
expect(queryByText('missing-custom-Text') !== null).toBeTruthy()
})
it('TestUIRendererError', async () => {
const {queryByText, queryAllByText, container} = render(
<TestUIRenderer data={{
demo_string: '4444a', demo_number: 83,
// @ts-ignore
demo_array: 'not-an-array',
}}/>
)
//expect(container).toMatchSnapshot()
expect(container.querySelectorAll('.root-renderer').length === 1).toBeTruthy()
expect(container.querySelectorAll('.group-renderer').length > 0).toBeTruthy()
//expect(queryByText('store-is-correct') === null).toBeTruthy()
//expect(queryByText('store-is-invalid') !== null).toBeTruthy()
expect(queryByText('widget.demo_string.title') !== null).toBeTruthy()
expect(queryByText('string-with-error') !== null).toBeTruthy()
expect(queryAllByText('string-renderer').length === 2).toBeTruthy()
})
})
Example #19
Source File: buildx.test.ts From build-push-action with Apache License 2.0 | 5 votes |
describe('getMetadata', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getMetadata();
expect(expected).toEqual(metadata);
});
});
Example #20
Source File: virustotal.test.ts From ghaction-virustotal with MIT License | 5 votes |
describe('virustotal', () => {
describe('mimeOrDefault', () => {
it('returns a specific mime for common path', async () => {
expect(mimeOrDefault('foo.tar.gz')).toEqual('application/gzip');
});
it('returns default mime for uncommon path', async () => {
expect(mimeOrDefault('foo.uncommon')).toEqual('application/octet-stream');
});
});
it('derives asset info from a path', async () => {
const {name, mime, size, file} = asset('tests/data/foo/bar.txt');
expect(name).toEqual('bar.txt');
expect(mime).toEqual('text/plain');
expect(size).toEqual(7);
expect(file.toString()).toEqual('scan me');
});
(process.env.VT_API_KEY ? it : it.skip)(
'uploads asset on VirusTotal',
async () => {
const vt: VirusTotal = new VirusTotal(process.env.VT_API_KEY);
await vt.files('tests/data/foo/bar.txt').then(upload => {
// eslint-disable-next-line jest/no-standalone-expect
expect(upload.id).not.toBeUndefined();
// eslint-disable-next-line jest/no-standalone-expect
expect(upload.url).not.toBeUndefined();
});
},
30000
);
(process.env.VT_MONITOR_API_KEY ? it : it.skip)(
'uploads asset on VirusTotal Monitor',
async () => {
const vt: VirusTotal = new VirusTotal(process.env.VT_MONITOR_API_KEY);
await vt.monitorItems('tests/data/foo/bar.txt', '/test').then(upload => {
// eslint-disable-next-line jest/no-standalone-expect
expect(upload.id).not.toBeUndefined();
// eslint-disable-next-line jest/no-standalone-expect
expect(upload.url).not.toBeUndefined();
});
},
30000
);
});
Example #21
Source File: buildx.test.ts From bake-action with Apache License 2.0 | 5 votes |
describe('getMetadata', () => {
it('matches', async () => {
const metadataFile = await buildx.getMetadataFile();
await fs.writeFileSync(metadataFile, metadata);
const expected = await buildx.getMetadata();
expect(expected).toEqual(metadata);
});
});
Example #22
Source File: buildx.test.ts From build-push-action with Apache License 2.0 | 5 votes |
describe('getVersion', () => {
it('valid', async () => {
const version = await buildx.getVersion();
expect(semver.valid(version)).not.toBeNull();
});
});
Example #23
Source File: git.test.ts From setup-buildx-action with Apache License 2.0 | 5 votes |
describe('git', () => {
it('returns git remote ref', async () => {
const ref: string = await git.getRemoteSha('https://github.com/docker/buildx.git', 'refs/pull/648/head');
expect(ref).toEqual('f11797113e5a9b86bd976329c5dbb8a8bfdfadfa');
});
});
Example #24
Source File: buildx.test.ts From build-push-action with Apache License 2.0 | 5 votes |
describe('getImageID', () => {
it('matches', async () => {
const imageIDFile = await buildx.getImageIDFile();
await fs.writeFileSync(imageIDFile, imageID);
const expected = await buildx.getImageID();
expect(expected).toEqual(imageID);
});
});
Example #25
Source File: context.test.ts From bake-action with Apache License 2.0 | 4 votes |
describe('getInputList', () => {
it('single line correctly', async () => {
await setInput('foo', 'bar');
const res = context.getInputList('foo');
expect(res).toEqual(['bar']);
});
it('multiline correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});
it('multiline and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
const res = context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('multiline values', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar`
);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc`,
'FOO=bar'
]);
});
it('multiline values with empty lines', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar
"EMPTYLINE=aaaa
bbbb
ccc"`
);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc`,
'FOO=bar',
`EMPTYLINE=aaaa
bbbb
ccc`
]);
});
it('multiline values without quotes', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc
FOO=bar`
);
const res = context.getInputList('secrets', true);
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
});
it('multiline values escape quotes', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbb""bbb
ccccccccc"
FOO=bar`
);
const res = context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbb"bbb
ccccccccc`,
'FOO=bar'
]);
});
});
Example #26
Source File: context.test.ts From build-push-action with Apache License 2.0 | 4 votes |
describe('getInputList', () => {
it('single line correctly', async () => {
await setInput('foo', 'bar');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar']);
});
it('multiline correctly', async () => {
setInput('foo', 'bar\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('empty lines correctly', async () => {
setInput('foo', 'bar\n\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('comma correctly', async () => {
setInput('foo', 'bar,baz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('empty result correctly', async () => {
setInput('foo', 'bar,baz,');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines correctly', async () => {
setInput('foo', 'bar\r\nbaz');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz']);
});
it('different new lines and comma correctly', async () => {
setInput('foo', 'bar\r\nbaz,bat');
const res = await context.getInputList('foo');
expect(res).toEqual(['bar', 'baz', 'bat']);
});
it('multiline and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('different new lines and ignoring comma correctly', async () => {
setInput('cache-from', 'user/app:cache\r\ntype=local,src=path/to/dir');
const res = await context.getInputList('cache-from', true);
expect(res).toEqual(['user/app:cache', 'type=local,src=path/to/dir']);
});
it('multiline values', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc`,
'FOO=bar'
]);
});
it('multiline values with empty lines', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc"
FOO=bar
"EMPTYLINE=aaaa
bbbb
ccc"`
);
const res = await context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc`,
'FOO=bar',
`EMPTYLINE=aaaa
bbbb
ccc`
]);
});
it('multiline values without quotes', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
MYSECRET=aaaaaaaa
bbbbbbb
ccccccccc
FOO=bar`
);
const res = await context.getInputList('secrets', true);
expect(res).toEqual(['GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789', 'MYSECRET=aaaaaaaa', 'bbbbbbb', 'ccccccccc', 'FOO=bar']);
});
it('large multiline values', async () => {
setInput(
'secrets',
`"GPG_KEY=${pgp}"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
expect(res).toEqual([`GPG_KEY=${pgp}`, 'FOO=bar']);
});
it('multiline values escape quotes', async () => {
setInput(
'secrets',
`GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789
"MYSECRET=aaaaaaaa
bbbb""bbb
ccccccccc"
FOO=bar`
);
const res = await context.getInputList('secrets', true);
expect(res).toEqual([
'GIT_AUTH_TOKEN=abcdefgh,ijklmno=0123456789',
`MYSECRET=aaaaaaaa
bbbb"bbb
ccccccccc`,
'FOO=bar'
]);
});
});
Example #27
Source File: number.spec.ts From ya-webadb with MIT License | 4 votes |
describe("Types", () => {
describe("Number", () => {
describe("NumberFieldType", () => {
describe('Int8', () => {
const key = "Int8";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 1);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
describe('Uint8', () => {
const key = "Uint8";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 1);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
describe('Int16', () => {
const key = "Int16";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 2);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
describe('Uint16', () => {
const key = "Uint16";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 2);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
describe('Int32', () => {
const key = "Int32";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 4);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
describe('Uint32', () => {
const key = "Uint32";
test('basic', () => {
expect(NumberFieldType[key]).toHaveProperty("size", 4);
expect(NumberFieldType[key]).toHaveProperty("dataViewSetter", "set" + key);
});
testDeserialize(NumberFieldType[key]);
});
});
describe("NumberFieldDefinition", () => {
describe("#getSize", () => {
it("should return size of its type", () => {
expect(new NumberFieldDefinition(NumberFieldType.Int8).getSize()).toBe(1);
expect(new NumberFieldDefinition(NumberFieldType.Uint8).getSize()).toBe(1);
expect(new NumberFieldDefinition(NumberFieldType.Int16).getSize()).toBe(2);
expect(new NumberFieldDefinition(NumberFieldType.Uint16).getSize()).toBe(2);
expect(new NumberFieldDefinition(NumberFieldType.Int32).getSize()).toBe(4);
expect(new NumberFieldDefinition(NumberFieldType.Uint32).getSize()).toBe(4);
});
});
describe("#deserialize", () => {
it("should deserialize Uint8", () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint8);
const struct = new StructValue({});
const value = definition.deserialize(
StructDefaultOptions,
stream,
struct,
);
expect(value.get()).toBe(1);
expect(read).toBeCalledTimes(1);
expect(read).lastCalledWith(NumberFieldType.Uint8.size);
});
it("should deserialize Uint16", () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint16);
const struct = new StructValue({});
const value = definition.deserialize(
StructDefaultOptions,
stream,
struct,
);
expect(value.get()).toBe((1 << 8) | 2);
expect(read).toBeCalledTimes(1);
expect(read).lastCalledWith(NumberFieldType.Uint16.size);
});
it("should deserialize Uint16LE", () => {
const read = jest.fn((length: number) => new Uint8Array([1, 2, 3, 4]));
const stream: StructDeserializeStream = { read };
const definition = new NumberFieldDefinition(NumberFieldType.Uint16);
const struct = new StructValue({});
const value = definition.deserialize(
{ ...StructDefaultOptions, littleEndian: true },
stream,
struct,
);
expect(value.get()).toBe((2 << 8) | 1);
expect(read).toBeCalledTimes(1);
expect(read).lastCalledWith(NumberFieldType.Uint16.size);
});
});
});
describe("NumberFieldValue", () => {
describe("#getSize", () => {
it("should return size of its definition", () => {
const struct = new StructValue({});
expect(
new NumberFieldDefinition(NumberFieldType.Int8)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(1);
expect(
new NumberFieldDefinition(NumberFieldType.Uint8)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(1);
expect(
new NumberFieldDefinition(NumberFieldType.Int16)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(2);
expect(
new NumberFieldDefinition(NumberFieldType.Uint16)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(2);
expect(
new NumberFieldDefinition(NumberFieldType.Int32)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(4);
expect(
new NumberFieldDefinition(NumberFieldType.Uint32)
.create(
StructDefaultOptions,
struct,
42,
)
.getSize()
).toBe(4);
});
});
describe("#serialize", () => {
it("should serialize uint8", () => {
const definition = new NumberFieldDefinition(NumberFieldType.Int8);
const struct = new StructValue({});
const value = definition.create(
StructDefaultOptions,
struct,
42,
);
const array = new Uint8Array(10);
const dataView = new DataView(array.buffer);
value.serialize(dataView, 2);
expect(Array.from(array)).toEqual([0, 0, 42, 0, 0, 0, 0, 0, 0, 0]);
});
});
});
});
});
Example #28
Source File: WidgetRenderer.test.tsx From ui-schema with MIT License | 4 votes |
describe('WidgetRenderer', () => {
it('missing type widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {}, custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={'demo-value'}
schema={createOrderedMap({type: 'string'})}
/>
)
expect(queryByText('missing-type-string') !== null).toBeTruthy()
})
it('missing custom widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {}, custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={'demo-value'}
schema={createOrderedMap({type: 'string', widget: 'Text'})}
/>
)
expect(queryByText('missing-custom-Text') !== null).toBeTruthy()
})
it('type widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {string: (props: WidgetProps) => props.value}, custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={'demo-value'}
schema={createOrderedMap({type: 'string'})}
/>
)
expect(queryByText('demo-value') !== null).toBeTruthy()
expect(queryByText('missing-type-string') === null).toBeTruthy()
})
it('custom widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {}, custom: {Text: (props: WidgetProps) => props.value},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={'demo-value'}
schema={createOrderedMap({type: 'string', widget: 'Text'})}
/>
)
expect(queryByText('demo-value') !== null).toBeTruthy()
expect(queryByText('missing-custom-Text') === null).toBeTruthy()
})
it('array widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {array: (props: WidgetProps) => typeof props.value === 'undefined' ? 'is-undef' : 'is-set'}, custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={[]}
schema={createOrderedMap({type: 'array'})}
/>
)
expect(queryByText('is-undef') !== null).toBeTruthy()
})
it('object widget', async () => {
const {queryByText} = render(
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: null,
WidgetRenderer: WidgetRenderer,
types: {},
custom: {CustomObj: (props: WidgetProps) => typeof props.value === 'undefined' ? 'is-undef' : 'is-set'},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={{}}
schema={createOrderedMap({type: 'object', widget: 'CustomObj'})}
/>
)
expect(queryByText('is-undef') !== null).toBeTruthy()
})
it('virtual widget object', async () => {
const value = createOrderedMap({dummy: ['lorem ipsum', 42]})
const store = createStore(value)
const {queryByText, queryAllByText} = render(
<UIStoreProvider
store={store}
// @ts-ignore
onChange={undefined}
>
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: () => null,
WidgetRenderer: WidgetRenderer,
types: {string: () => 'string-renderer', number: () => 'number-renderer'},
custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={value}
virtualWidgets={virtualWidgets}
storeKeys={List()}
schema={createOrderedMap({
type: 'object',
properties: {
dummy: {
type: 'string',
},
dummy_nr: {
type: 'number',
},
},
})}
isVirtual
/>
</UIStoreProvider>
)
expect(queryAllByText('virtual-default-renderer').length === 2).toBeTruthy()
expect(queryByText('string-renderer') === null).toBeTruthy()
expect(queryByText('number-renderer') === null).toBeTruthy()
})
it('virtual widget object w-values', async () => {
const virtualWidgets2: VirtualWidgetsMapping = {
default: virtualWidgets.default_w_suffix,
array: VirtualArrayRenderer,
object: ObjectRenderer,
}
const schema = createOrderedMap({
type: 'object',
properties: {
dummy_string: {type: 'string'},
dummy_string2: {type: 'string'},
},
})
const value = createOrderedMap({
dummy_string: 'lorem_ipsum',
dummy_string2: 'dolor_sit',
})
const store = createStore(value)
const {queryByText, container} = render(
<UIStoreProvider
store={store}
// @ts-ignore
onChange={undefined}
>
<WidgetRenderer
widgets={{
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: () => null,
WidgetRenderer: WidgetRenderer,
types: {string: () => 'string-renderer', number: () => 'number-renderer'},
custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}}
value={value}
virtualWidgets={virtualWidgets2}
storeKeys={List()}
schema={schema}
isVirtual
/>
</UIStoreProvider>
)
expect(container.querySelector('#virtual-default-renderer__lorem_ipsum') !== null).toBeTruthy()
expect(container.querySelector('#virtual-default-renderer__dolor_sit') !== null).toBeTruthy()
expect(queryByText('string-renderer') === null).toBeTruthy()
expect(queryByText('number-renderer') === null).toBeTruthy()
})
it('virtual widget w-tuple', async () => {
const virtualWidgets2: VirtualWidgetsMapping = {
default: virtualWidgets.default,
array: VirtualArrayRenderer,
object: ObjectRenderer,
}
const widgets = {
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: () => null,
WidgetRenderer: WidgetRenderer,
types: {string: () => 'string-renderer', number: () => 'number-renderer'},
custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}
const value = createOrderedMap({dummy_array: ['lorem ipsum', 42]})
const store = createStore(value)
const {queryByText, queryAllByText} = render(
// @ts-ignore
<UIMetaProvider widgets={widgets} t={relTranslator}>
<UIStoreProvider
store={store}
// @ts-ignore
onChange={undefined}
>
<WidgetRenderer
widgets={widgets}
value={value}
virtualWidgets={virtualWidgets2}
storeKeys={List()}
schema={createOrderedMap({
type: 'object',
properties: {
dummy: {type: 'string'},
dummy_array: {
type: 'array',
items: [
{type: 'string'},
{type: 'number'},
],
},
},
})}
isVirtual
/>
</UIStoreProvider>
</UIMetaProvider>
)
expect(queryAllByText('virtual-default-renderer').length).toBe(3)
expect(queryByText('string-renderer') === null).toBeTruthy()
expect(queryByText('number-renderer') === null).toBeTruthy()
})
it('virtual widget w-array', async () => {
const virtualWidgets2: VirtualWidgetsMapping = {
default: virtualWidgets.default,
array: VirtualArrayRenderer,
object: ObjectRenderer,
}
const widgets = {
// @ts-ignore
RootRenderer: null, GroupRenderer: null, ErrorFallback: () => null,
WidgetRenderer: WidgetRenderer,
types: {string: () => 'string-renderer', number: () => 'number-renderer'},
custom: {},
pluginStack: [ExtractStorePlugin],
pluginSimpleStack: [],
}
const value = createOrderedMap({dummy_array: [['lorem ipsum', 42], ['dolor sit', 43]]})
const store = createStore(value)
const {queryByText, queryAllByText} = render(
// @ts-ignore
<UIMetaProvider widgets={widgets} t={relTranslator}>
<UIStoreProvider
store={store}
// @ts-ignore
onChange={undefined}
>
<WidgetRenderer
widgets={widgets}
value={value}
storeKeys={List()}
virtualWidgets={virtualWidgets2}
schema={createOrderedMap({
type: 'object',
properties: {
dummy: {type: 'string'},
dummy_array: {
type: 'array',
items: {
type: 'array',
items: [
{type: 'string'},
{type: 'number'},
],
},
},
},
})}
isVirtual
/>
</UIStoreProvider>
</UIMetaProvider>
)
expect(queryAllByText('virtual-default-renderer').length).toBe(5)
expect(queryByText('string-renderer') === null).toBeTruthy()
expect(queryByText('number-renderer') === null).toBeTruthy()
})
})