Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.

Remove path aliases from tests #2243

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/test-a-feature.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ These tests are typically imported into individual component tests.
Every common test receives your component as its first argument.

```tsx
import { isConformant } from 'test/specs/commonTests'
import { isConformant } from '../../commonTests'

import Divider from 'src/components/Divider/Divider'
import { Divider } from '@fluentui/react'

describe('Divider', () => {
isConformant(Divider)
Expand Down Expand Up @@ -85,9 +85,9 @@ There should be one describe block for each prop of your component.
Example for `Button` component:

```tsx
import { isConformant } from 'test/specs/commonTests'
import { isConformant } from '../../commonTests'

import Button from 'src/components/Button'
import { Button } from '@fluentui/react'

describe('Button', () => {
isConformant(Button)
Expand Down Expand Up @@ -242,7 +242,7 @@ Add your spec file into the array of files `skipSpecChecksForFiles` in `testHelp

## Performance Tests

Performance tests will measure performance, set a baseline for performance and help guard against regressions.
Performance tests will measure performance, set a baseline for performance and help guard against regressions.

### Adding a Perf Test

Expand Down
5 changes: 4 additions & 1 deletion build/screener/screener.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
require('@fluentui/internal-tooling/babel/register')

const config = require('../config').default
const { compilerOptions } = require('../tsconfig.docs.json')

// Ensure that paths to local packages are interpreted properly
// (see https://github.com/microsoft/fluent-ui-react/pull/837)
const { compilerOptions } = require('../../tsconfig.json')

require('tsconfig-paths').register({
baseUrl: config.path_base,
Expand Down
8 changes: 0 additions & 8 deletions build/tsconfig.common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
"module": "commonjs",
"target": "es5",
"lib": ["es2015", "dom"],
"baseUrl": "../",
"paths": {
"@fluentui/docs": ["docs"],
"@fluentui/e2e": ["e2e"],
"@fluentui/internal-tooling": ["build"],
"@fluentui/perf": ["perf"],
"@fluentui/*": ["packages/*/src"]
},
"types": ["node", "jest"],
"typeRoots": ["../types", "../node_modules/@types"],
"jsx": "react",
Expand Down
1 change: 1 addition & 0 deletions build/tsconfig.docs.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
"extends": "./tsconfig.common.json",
"compilerOptions": {
"module": "esnext",
"baseUrl": "../",
"paths": {
"@fluentui/*": ["packages/*/src"],
"docs/*": ["docs/*"],
Expand Down
12 changes: 7 additions & 5 deletions gulpfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ import * as tsPaths from 'tsconfig-paths'

import config from './build/config'

const { compilerOptions } = require('./build/tsconfig.docs.json')

// add node_modules/.bin to the path so we can invoke .bin CLIs in tasks
process.env.PATH =
process.env.PATH + path.delimiter + path.resolve(__dirname, 'node_modules', '.bin')
// Ensure that paths to local packages are interpreted properly
// (see https://github.com/microsoft/fluent-ui-react/pull/837)
const { compilerOptions } = require('./tsconfig.json')

tsPaths.register({
baseUrl: config.path_base,
paths: compilerOptions.paths,
})

// add node_modules/.bin to the path so we can invoke .bin CLIs in tasks
process.env.PATH =
process.env.PATH + path.delimiter + path.resolve(__dirname, 'node_modules', '.bin')

// load tasks in order of dependency usage
require('./build/gulp/tasks/bundle')
require('./build/gulp/tasks/docs')
Expand Down
1 change: 1 addition & 0 deletions packages/accessibility/test/behaviors/behavior-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
import { TestHelper } from './testHelper'
import definitions from './testDefinitions'

// TODO (@ecraig12345) - remove relative docs import
const behaviorMenuItems = require('../../../../docs/src/behaviorMenu')

const testHelper = new TestHelper()
Expand Down
7 changes: 6 additions & 1 deletion packages/accessibility/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"extends": "../../build/tsconfig.common",
"compilerOptions": {
"composite": true,
"outDir": "dist/dts"
"outDir": "dist/dts",
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/accessibility": ["./src"]
}
},
"include": ["src", "test"]
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This is not exported
import getKeyDownHandlers from '../../src/accessibility/getKeyDownHandlers'
// @ts-ignore
import * as keyboardKey from 'keyboard-key'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// This is not exported
import shouldHandleOnKeys from '../../src/accessibility/shouldHandleOnKeys'

const getEventArg = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
emptyTheme,
ICSSInJSStyle,
} from '@fluentui/styles'
// This is not exported
import resolveStylesAndClasses from '../../src/styles/resolveStylesAndClasses'

const styleParam: ComponentStyleFunctionParam = {
Expand Down
7 changes: 6 additions & 1 deletion packages/react-bindings/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"strictNullChecks": true
"strictNullChecks": true,
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-bindings": ["./src"]
}
},
"include": ["src", "test"],
"references": [
Expand Down
7 changes: 6 additions & 1 deletion packages/react-component-event-listener/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"strictNullChecks": true
"strictNullChecks": true,
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-component-event-listener": ["./src"]
}
},
"include": ["src", "test"],
"references": []
Expand Down
7 changes: 6 additions & 1 deletion packages/react-component-nesting-registry/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"strictNullChecks": true
"strictNullChecks": true,
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-component-nesting-registry": ["./src"]
}
},
"include": ["src", "test"],
"references": []
Expand Down
7 changes: 6 additions & 1 deletion packages/react-component-ref/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@
"noImplicitThis": true,
"noImplicitAny": true,
"noUnusedParameters": true,
"strictNullChecks": true
"strictNullChecks": true,
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-component-ref": ["./src"]
}
},
"include": ["src", "test"],
"references": []
Expand Down
7 changes: 6 additions & 1 deletion packages/react-proptypes/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
"extends": "../../build/tsconfig.common",
"compilerOptions": {
"composite": true,
"outDir": "dist/dts"
"outDir": "dist/dts",
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-proptypes": ["./src"]
}
},
"include": ["src", "test"],
"references": []
Expand Down
7 changes: 6 additions & 1 deletion packages/react-theming/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@
"compilerOptions": {
"composite": true,
"rootDir": "src",
"outDir": "lib"
"outDir": "lib",
"baseUrl": ".",
"paths": {
// For tests
"@fluentui/react-theming": ["./src"]
}
},
"include": ["src"]
}
9 changes: 1 addition & 8 deletions packages/react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,5 @@ const commonConfig = require('@fluentui/internal-tooling/jest')
module.exports = {
...commonConfig,
name: 'react',
moduleNameMapper: {
...require('lerna-alias').jest(),
'docs/(.*)$': `<rootDir>/../../docs/$1`,

// Legacy aliases, they should not be used in new tests
'^src/(.*)$': `<rootDir>/src/$1`,
'test/(.*)$': `<rootDir>/test/$1`,
},
moduleNameMapper: require('lerna-alias').jest(),
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import { FocusZone, FOCUSZONE_WRAP_ATTRIBUTE } from '@fluentui/react-bindings'
import * as React from 'react'
import * as keyboardKey from 'keyboard-key'

import { mountWithProviderAndGetComponent, mountWithProvider } from 'test/utils'
import { UIComponent } from 'src/utils'
import { mountWithProviderAndGetComponent, mountWithProvider } from '../../utils'
import { UIComponent } from '@fluentui/react'
import { EVENT_TARGET_ATTRIBUTE, getEventTargetComponent } from './eventTarget'

export const getRenderedAttribute = (renderedComponent, propName, partSelector) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import * as ReactDOMServer from 'react-dom/server'
import { axe, toHaveNoViolations } from 'jest-axe'
import { EmptyThemeProvider } from 'test/utils'
import { EmptyThemeProvider } from '../../utils'

type AxeMatcher<R> = jest.Matchers<R, any> & {
toHaveNoViolations: () => R
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { mountWithProvider as mount } from 'test/utils'
import { mountWithProvider as mount } from '../../utils'
import * as _ from 'lodash'
import { PropsOf } from 'src/types'
import { PropsOf } from '@fluentui/react'

export type CollectionShorthandTestOptions<TProps = any> = {
mapsValueToProp: keyof (TProps & React.HTMLProps<HTMLElement>) | false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from 'react'
import { ReactWrapper } from 'enzyme'
import { mountWithProvider } from 'test/utils'
import { Props, PropsOf, InstanceOf } from 'src/types'
import { mountWithProvider } from '../../utils'
import { Props, PropsOf, InstanceOf } from '@fluentui/react'

export type ShorthandTestOptions<TProps = any> = {
mapsValueToProp: keyof (TProps & React.HTMLProps<HTMLElement>) | false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import * as React from 'react'
import { ReactWrapper } from 'enzyme'
import { mountWithProvider as mount } from 'test/utils'
import { mountWithProvider as mount } from '../../utils'

import Box from 'src/components/Box/Box'
import { Props, ShorthandValue } from 'src/types'
import { Box, Props, ShorthandValue } from '@fluentui/react'

export interface ImplementsWrapperPropOptions {
wrapppedComponentSelector: any
Expand Down
9 changes: 5 additions & 4 deletions packages/react/test/specs/commonTests/isConformant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import {
getDisplayName,
mountWithProvider as mount,
syntheticEvent,
} from 'test/utils'
} from '../../utils'
import helpers from './commonHelpers'

import * as FluentUI from 'src/index'
import * as FluentUI from '@fluentui/react'
import { getEventTargetComponent, EVENT_TARGET_ATTRIBUTE } from './eventTarget'

export interface Conformant {
Expand Down Expand Up @@ -112,7 +112,8 @@ export default function isConformant(
// This is pretty ugly because:
// - jest doesn't support custom error messages
// - jest will run all test
const infoJSONPath = `docs/src/componentInfo/${constructorName}.info.json`
// TODO (@ecraig12345) - remove relative docs import
const infoJSONPath = `../../../../../docs/src/componentInfo/${constructorName}.info.json`

let info

Expand All @@ -124,7 +125,7 @@ export default function isConformant(
throw new Error(
[
'!! ==========================================================',
`!! Missing ${infoJSONPath}.`,
`!! Missing ${infoJSONPath.replace('../../../../../', '')}.`,
'!! Run `yarn test` or `yarn test:watch` again to generate one.',
'!! ==========================================================',
].join('\n'),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import * as _ from 'lodash'
import * as FluentUI from 'src/index'
import * as FluentUI from '@fluentui/react'

// ----------------------------------------
// Is exported or private
Expand All @@ -12,7 +12,7 @@ export default (constructorName: string, displayName: string) => {
test('is exported at the top level', () => {
const message = [
`'${displayName}' must be exported at top level.`,
"Export it in 'src/index.js'.",
"Export it in 'src/index.ts'.",
].join(' ')

expect({ isTopLevelAPIProp, message }).toEqual({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ import { Extendable, ICSSInJSStyle } from '@fluentui/styles'
import * as React from 'react'
import * as PropTypes from 'prop-types'
import * as _ from 'lodash'
import { UIComponent } from 'src/utils'
import { mountWithProviderAndGetComponent } from 'test/utils'
import { UIComponent } from '@fluentui/react'
import { mountWithProviderAndGetComponent } from '../../utils'

type AttrValue = 'props' | 'state'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import * as React from 'react'
import * as keyboardKey from 'keyboard-key'

import Accordion from 'src/components/Accordion/Accordion'
import { isConformant, handlesAccessibility } from 'test/specs/commonTests'
import { mountWithProvider, mountWithProviderAndGetComponent } from 'test/utils'
import AccordionTitle from 'src/components/Accordion/AccordionTitle'
import { Accordion, AccordionTitle } from '@fluentui/react'
import { isConformant, handlesAccessibility } from '../../commonTests'
import { mountWithProvider, mountWithProviderAndGetComponent } from '../../../utils'
import { ReactWrapper, CommonWrapper } from 'enzyme'

const panels = [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import * as React from 'react'

import AccordionContent from 'src/components/Accordion/AccordionContent'
import { isConformant, handlesAccessibility, getRenderedAttribute } from 'test/specs/commonTests'
import { mountWithProviderAndGetComponent } from 'test/utils'
import { AccordionContent } from '@fluentui/react'
import { isConformant, handlesAccessibility, getRenderedAttribute } from '../../commonTests'
import { mountWithProviderAndGetComponent } from '../../../utils'

describe('AccordionContent', () => {
isConformant(AccordionContent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import AccordionTitle from 'src/components/Accordion/AccordionTitle'
import { isConformant, handlesAccessibility } from 'test/specs/commonTests'
import { AccordionTitle } from '@fluentui/react'
import { isConformant, handlesAccessibility } from '../../commonTests'

describe('AccordionTitle', () => {
isConformant(AccordionTitle, {
Expand Down
6 changes: 2 additions & 4 deletions packages/react/test/specs/components/Alert/Alert-test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,9 @@ import {
implementsShorthandProp,
handlesAccessibility,
htmlIsAccessibilityCompliant,
} from 'test/specs/commonTests'
} from '../../commonTests'

import Alert from 'src/components/Alert/Alert'
import Box from 'src/components/Box/Box'
import Button from 'src/components/Button/Button'
import { Alert, Box, Button } from '@fluentui/react'

const alertImplementsShorthandProp = implementsShorthandProp(Alert)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isConformant } from 'test/specs/commonTests'
import { isConformant } from '../../commonTests'

import Animation from 'src/components/Animation/Animation'
import { Animation } from '@fluentui/react'

describe('Animation', () => {
isConformant(Animation, { hasAccessibilityProp: false })
Expand Down
Loading