// TODO: better tests. these are way too generic. import { parse } from 'svelte/compiler' import { collectFormatCalls, collectMessageDefinitions, collectMessages, extractMessages, } from '../../src/cli/extract' describe('collecting format calls', () => { test('returns nothing if there are no imports', () => { const ast = parse(``) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(0) }) test('returns nothing if there are no format imports', () => { const ast = parse( `` ) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(0) }) test('collects all format calls in the instance script', () => { const ast = parse(``) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(2) expect(calls[0]).toMatchObject({ type: 'CallExpression' }) expect(calls[1]).toMatchObject({ type: 'CallExpression' }) }) test('collects all format calls with renamed imports', () => { const ast = parse(``) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(3) expect(calls[0]).toMatchObject({ type: 'CallExpression' }) expect(calls[1]).toMatchObject({ type: 'CallExpression' }) expect(calls[2]).toMatchObject({ type: 'CallExpression' }) }) test('collects all string format utility calls', () => { const ast = parse(``) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(4) expect(calls[0]).toMatchObject({ type: 'CallExpression' }) expect(calls[1]).toMatchObject({ type: 'CallExpression' }) expect(calls[2]).toMatchObject({ type: 'CallExpression' }) expect(calls[3]).toMatchObject({ type: 'CallExpression' }) }) test('ignores date, time and number calls', () => { const ast = parse(``) const calls = collectFormatCalls(ast) expect(calls).toHaveLength(0) }) }) describe('collecting message definitions', () => { test('returns nothing if there are no imports from the library', () => { const ast = parse( `` ) expect(collectMessageDefinitions(ast)).toHaveLength(0) }) test('gets all message definition objects', () => { const ast = parse(``) const definitions = collectMessageDefinitions(ast) expect(definitions).toHaveLength(4) expect(definitions[0]).toMatchObject({ type: 'ObjectExpression' }) expect(definitions[1]).toMatchObject({ type: 'ObjectExpression' }) expect(definitions[2]).toMatchObject({ type: 'ObjectExpression' }) expect(definitions[3]).toMatchObject({ type: 'ObjectExpression' }) }) }) describe('collecting messages', () => { test('collects all messages in both instance and html ASTs', () => { const markup = `