From 38acabfa6089ab8ac469c12b5f55022fb96935e5 Mon Sep 17 00:00:00 2001 From: Sebastian Date: Mon, 23 Aug 2021 16:46:06 -0300 Subject: added web vendors --- .../babel/__tests__/evaluators/preeval.test.ts | 121 +++++++++++++++++++++ 1 file changed, 121 insertions(+) create mode 100644 @linaria/packages/babel/__tests__/evaluators/preeval.test.ts (limited to '@linaria/packages/babel/__tests__/evaluators/preeval.test.ts') diff --git a/@linaria/packages/babel/__tests__/evaluators/preeval.test.ts b/@linaria/packages/babel/__tests__/evaluators/preeval.test.ts new file mode 100644 index 0000000..307abd7 --- /dev/null +++ b/@linaria/packages/babel/__tests__/evaluators/preeval.test.ts @@ -0,0 +1,121 @@ +import { join } from 'path'; +import { transformAsync } from '@babel/core'; +import dedent from 'dedent'; +import serializer from '../../__utils__/linaria-snapshot-serializer'; +import type { StrictOptions } from '../../src'; + +expect.addSnapshotSerializer(serializer); + +const options: Partial = { + displayName: true, + evaluate: true, +}; + +const transpile = async (input: string) => + (await transformAsync(input, { + babelrc: false, + presets: [[require.resolve('@linaria/preeval'), options]], + plugins: [ + '@babel/plugin-proposal-class-properties', + '@babel/plugin-syntax-jsx', + ], + filename: join(__dirname, 'app/index.js'), + configFile: false, + }))!; + +it('preserves classNames', async () => { + const { code } = await transpile( + dedent` + import { styled } from '@linaria/react'; + + const Component = styled.div\`\`; + ` + ); + + expect(code).toMatchSnapshot(); +}); + +it('handles locally named import', async () => { + const { code } = await transpile( + dedent` + import { styled as custom } from '@linaria/react'; + + const Component = custom.div\`\`; + ` + ); + + expect(code).toMatchSnapshot(); +}); + +it('replaces functional component', async () => { + const div = '
{props.children}
'; + const { code } = await transpile( + dedent` + import React from 'react'; + + const Component = (props) => ${div}; + ` + ); + + expect(code).toMatchSnapshot(); +}); + +it('replaces class component', async () => { + const div = '
{props.children}
'; + const { code } = await transpile( + dedent` + import React from 'react'; + + class Component extends React.PureComponent { + render() { + return ${div}; + } + } + ` + ); + + expect(code).toMatchSnapshot(); +}); + +it('replaces constant', async () => { + const div = '
{props.children}
'; + const { code } = await transpile( + dedent` + import React from 'react'; + + const tag = ${div}; + + const Component = (props) => tag; + ` + ); + + expect(code).toMatchSnapshot(); +}); + +it('hoists exports', async () => { + const { code } = await transpile( + dedent` + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + Object.defineProperty(exports, "foo", { + enumerable: true, + get: function get() { + return _foo.foo; + } + }); + Object.defineProperty(exports, "bar", { + enumerable: true, + get: function get() { + return _foo.bar; + } + }); + + var _foo = require("./foo"); + ` + ); + + expect(code).toMatchSnapshot(); +}); -- cgit v1.2.3