-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
figma-bot
committed
Jul 10, 2024
1 parent
810f271
commit 9911b18
Showing
24 changed files
with
846 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 1 addition & 0 deletions
1
cli/src/__test__/e2e_connect_command/dummy_api_response_for_wizard.json
Large diffs are not rendered by default.
Oops, something went wrong.
16 changes: 16 additions & 0 deletions
16
cli/src/__test__/e2e_connect_command/react_wizard/components/PrimaryButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import React from 'react' | ||
|
||
interface ButtonProps { | ||
disabled: boolean | ||
children: any | ||
} | ||
|
||
/** | ||
* @description This is a button | ||
* @param children text to render | ||
* @param disabled disable the button | ||
* @returns JSX element | ||
*/ | ||
export const PrimaryButton = ({ children, disabled = false }: ButtonProps) => { | ||
return <button disabled={disabled}>{children}</button> | ||
} |
15 changes: 15 additions & 0 deletions
15
cli/src/__test__/e2e_connect_command/react_wizard/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"name": "tests", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"keywords": [], | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"react": "^18.3.1" | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
cli/src/__test__/e2e_connect_command/react_wizard/tsconfig.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"jsx": "react-jsx", | ||
"outDir": "dist", | ||
"module": "commonjs", | ||
"target": "es6", | ||
"esModuleInterop": true, | ||
"skipLibCheck": true, | ||
}, | ||
"include": ["**/*.tsx"], | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import { promisify } from 'util' | ||
import { exec } from 'child_process' | ||
import { LONG_TEST_TIMEOUT_MS, tidyStdOutput } from './utils' | ||
import fs from 'fs' | ||
import path from 'path' | ||
|
||
describe('e2e test for the wizard', () => { | ||
let result: { | ||
stdout: string | ||
stderr: string | ||
} | ||
|
||
const testPath = path.join(__dirname, 'e2e_connect_command/react_wizard') | ||
|
||
beforeAll(async () => { | ||
const mockDocPath = path.join( | ||
__dirname, | ||
'e2e_connect_command/dummy_api_response_for_wizard.json', | ||
) | ||
|
||
const wizardAnswers = [ | ||
'figd_123', // Access token | ||
'./e2e_connect_command/react_wizard/components', // Top-level components directory | ||
'https://www.figma.com/design/abc123/my-design-system', // Design system URL | ||
'yes', // Confirm create a new config file | ||
'', // Don't select any links to edit | ||
'', // co-locate CC files | ||
] | ||
|
||
const escapedStringifiedJson = JSON.stringify(wizardAnswers).replace(/"/g, '\\"') | ||
|
||
result = await promisify(exec)( | ||
`npx cross-env CODE_CONNECT_MOCK_DOC_RESPONSE=${mockDocPath} WIZARD_ANSWERS_TO_PREFILL="${escapedStringifiedJson}" npx tsx ../cli connect --dir ${testPath}`, | ||
{ | ||
cwd: __dirname, | ||
}, | ||
) | ||
}, LONG_TEST_TIMEOUT_MS) | ||
|
||
afterAll(() => { | ||
fs.rmSync(path.join(testPath, 'figma.config.json'), { force: true }) | ||
fs.rmSync(path.join(testPath, 'components/PrimaryButton.figma.tsx'), { force: true }) | ||
}) | ||
|
||
it('starts the wizard', () => { | ||
expect(tidyStdOutput(result.stderr)).toContain('Welcome to Code Connect') | ||
}) | ||
|
||
it('creates config file from given answers', () => { | ||
const configPath = path.join(testPath, 'figma.config.json') | ||
expect(fs.readFileSync(configPath, 'utf8')).toBe(`\ | ||
{ | ||
"codeConnect": { | ||
"include": ["components/**/*.{tsx,jsx}"] | ||
} | ||
} | ||
`) | ||
}) | ||
|
||
it('reaches linking step', () => { | ||
expect(tidyStdOutput(result.stderr)).toContain('Connecting your components') | ||
}) | ||
|
||
it('creates Code Connect file at correct location', () => { | ||
const codeConnectPath = path.join(testPath, 'components/PrimaryButton.figma.tsx') | ||
expect(tidyStdOutput(result.stderr)).toContain(`Created ${codeConnectPath}`) | ||
const exists = fs.existsSync(codeConnectPath) | ||
expect(exists).toBe(true) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { CodeConnectReactConfig, resolveImportPath } from '../project' | ||
|
||
describe('Project helper functions', () => { | ||
function getConfig(importPaths: {}): CodeConnectReactConfig { | ||
return { | ||
parser: 'react', | ||
...importPaths, | ||
} | ||
} | ||
|
||
describe('importPath mappings', () => { | ||
it('Matches a simple import path', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/button.tsx', | ||
getConfig({ importPaths: { 'src/button.tsx': '@ui/button' } }), | ||
) | ||
expect(mapped).toEqual('@ui/button') | ||
}) | ||
|
||
it('Matches a wildcard import path', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/button.tsx', | ||
getConfig({ importPaths: { 'src/*': '@ui' } }), | ||
) | ||
expect(mapped).toEqual('@ui') | ||
}) | ||
|
||
it('Matches a wildcard import path with a wildcard output path', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/button.tsx', | ||
getConfig({ importPaths: { 'src/*': '@ui/*' } }), | ||
) | ||
expect(mapped).toEqual('@ui/button') | ||
}) | ||
|
||
it('Matches a wildcard import path with a nested directory', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/components/button.tsx', | ||
getConfig({ importPaths: { 'src/*': '@ui' } }), | ||
) | ||
expect(mapped).toEqual('@ui') | ||
}) | ||
|
||
it('Matches a wildcard import path and output path with a nested directory', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/components/button.tsx', | ||
getConfig({ importPaths: { 'src/*': '@ui/*' } }), | ||
) | ||
expect(mapped).toEqual('@ui/button') | ||
}) | ||
|
||
it('Passing only a wildcard matches any import', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/components/button.tsx', | ||
getConfig({ importPaths: { '*': '@ui' } }), | ||
) | ||
expect(mapped).toEqual('@ui') | ||
}) | ||
|
||
it('Returns null for non-matching paths', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/button.tsx', | ||
getConfig({ importPaths: { 'src/components/*': '@ui' } }), | ||
) | ||
expect(mapped).toBeNull() | ||
}) | ||
|
||
it('Should pick the first match if there are multiple mappings', () => { | ||
const mapped = resolveImportPath( | ||
'/Users/test/app/src/icons/icon.tsx', | ||
getConfig({ importPaths: { 'icons/*': '@ui/icons', 'src/*': '@ui' } }), | ||
) | ||
expect(mapped).toEqual('@ui/icons') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.