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

Commit 012fedf

Browse files
authored
chore: Run tests per-package (#2170)
1 parent f24754a commit 012fedf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+567
-179
lines changed

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
command: yarn prettier
4646
- run:
4747
name: Unit Tests
48-
command: yarn test --maxWorkers=2
48+
command: yarn test
4949
- run:
5050
name: Report coverage
5151
command: bash <(curl -s https://codecov.io/bash)

.github/CONTRIBUTING.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
44
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->
55

6-
76
- [Getting started](#getting-started)
87
- [Useful Commands](#useful-commands)
98
- [Workflow](#workflow)
@@ -168,11 +167,11 @@ These changes are required to setup internal tooling and package publishing.
168167
- "test": "echo \"Error: run tests from root\" && exit 1"
169168
- },
170169
+ "scripts": {
171-
+ "build": "gulp bundle:package:no-umd --package react-proptypes"
170+
+ "build": "gulp bundle:package:no-umd"
172171
+ },
173172
```
174173

175-
Don't forget to provide a correct directory name, you can also use `gulp bundle:package` to bundle your package with UMD.
174+
You can also use `gulp bundle:package` to bundle your package with UMD.
176175

177176
#### Create `tsconfig.json`
178177

.gulp.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
// https://github.com/gulpjs/gulp-cli#configuration
2+
module.exports = {
3+
flags: {
4+
require: '@fluentui/internal-tooling/babel/register',
5+
},
6+
}

.gulp.json

Lines changed: 0 additions & 5 deletions
This file was deleted.

azure-pipelines.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,17 @@ trigger: [master]
1010
pool:
1111
vmImage: 'ubuntu-latest'
1212

13-
steps:
14-
- task: ComponentGovernanceComponentDetection@0
15-
inputs:
16-
scanType: 'Register'
17-
verbosity: 'Verbose'
18-
alertWarningLevel: 'High'
19-
displayName: Component governance registration
13+
variables:
14+
# emulate circleci method of detecting whether build is running in CI or local
15+
CI: 1
2016

17+
steps:
18+
- task: ComponentGovernanceComponentDetection@0
19+
inputs:
20+
scanType: 'Register'
21+
verbosity: 'Verbose'
22+
alertWarningLevel: 'High'
23+
displayName: Component governance registration
2124
# Rest of build is not being used for now, but leaving setup for reference
2225

2326
# - task: NodeTool@0

build/gulp/tasks/bundle.ts

Lines changed: 18 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
import { task, series, parallel, src, dest } from 'gulp'
22
import babel from 'gulp-babel'
3-
import rimraf from 'rimraf'
3+
import del from 'del'
44
import webpack from 'webpack'
5-
import { argv } from 'yargs'
65

76
import config from '../../../config'
87
import sh from '../sh'
@@ -12,27 +11,19 @@ const g = require('gulp-load-plugins')()
1211
const { paths } = config
1312
const { log, PluginError } = g.util
1413

15-
const packageName = (argv.package as string) || 'react'
14+
const packageName = config.package
1615

1716
// ----------------------------------------
1817
// Clean
1918
// ----------------------------------------
2019

21-
task('bundle:package:clean:es', cb => {
22-
rimraf(`${config.paths.packageDist(packageName)}/es/*`, cb)
23-
})
24-
25-
task('bundle:package:clean:commonjs', cb => {
26-
rimraf(`${config.paths.packageDist(packageName)}/commonjs/*`, cb)
27-
})
28-
29-
task('bundle:package:clean:umd', cb => {
30-
rimraf(`${config.paths.packageDist(packageName)}/umd/*`, cb)
31-
})
32-
33-
task(
34-
'bundle:package:clean',
35-
parallel('bundle:package:clean:es', 'bundle:package:clean:commonjs', 'bundle:package:clean:umd'),
20+
task('bundle:package:clean', () =>
21+
del([
22+
`${paths.packageDist(packageName)}/es/*`,
23+
`${paths.packageDist(packageName)}/commonjs/*`,
24+
`${paths.packageDist(packageName)}/umd/*`,
25+
`${paths.packageDist(packageName)}/dts`,
26+
]),
3627
)
3728

3829
// ----------------------------------------
@@ -51,11 +42,17 @@ task('bundle:package:commonjs', () =>
5142

5243
task('bundle:package:es', () =>
5344
src(componentsSrc)
54-
.pipe(babel({ caller: { useESModules: true } }))
45+
.pipe(babel({ caller: { useESModules: true } } as any))
5546
.pipe(dest(paths.packageDist(packageName, 'es'))),
5647
)
5748

58-
task('bundle:package:types:tsc', () => sh(`cd packages/${packageName} && tsc -b`))
49+
task('bundle:package:types:tsc', () => {
50+
let cmd = 'tsc -b'
51+
if (process.cwd() === config.path_base) {
52+
cmd = `cd packages && cd ${packageName} && ${cmd}`
53+
}
54+
return sh(cmd)
55+
})
5956
task('bundle:package:types:copy', () => {
6057
return src(paths.packageDist(packageName, 'dts/src/**/*.d.ts')).pipe(
6158
dest(paths.packageDist(packageName, 'es')),
@@ -104,5 +101,5 @@ task('bundle:package', series('bundle:package:no-umd', 'bundle:package:umd'))
104101

105102
task('bundle:all-packages', async () => {
106103
await sh('lerna run build')
107-
rimraf.sync(`${config.paths.packages()}/*/dist/dts`)
104+
return del(`${config.paths.packages()}/*/dist/dts`)
108105
})

build/gulp/tasks/docs.ts

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import cache from 'gulp-cache'
44
import remember from 'gulp-remember'
55
import fs from 'fs'
66
import path from 'path'
7-
import rimraf from 'rimraf'
7+
import del from 'del'
88
import through2 from 'through2'
99
import webpack from 'webpack'
1010
import WebpackDevMiddleware from 'webpack-dev-middleware'
@@ -28,11 +28,11 @@ const g = require('gulp-load-plugins')()
2828

2929
const { log } = g.util
3030

31-
const logWatchAdd = filePath => log('Created', chalk.blue(path.basename(filePath)))
32-
const logWatchChange = filePath => log('Changed', chalk.magenta(path.basename(filePath)))
33-
const logWatchUnlink = filePath => log('Deleted', chalk.red(path.basename(filePath)))
31+
const logWatchAdd = (filePath: string) => log('Created', chalk.blue(path.basename(filePath)))
32+
const logWatchChange = (filePath: string) => log('Changed', chalk.magenta(path.basename(filePath)))
33+
const logWatchUnlink = (filePath: string) => log('Deleted', chalk.red(path.basename(filePath)))
3434

35-
const handleWatchUnlink = (group, filePath) => {
35+
const handleWatchUnlink = (group: any, filePath: string) => {
3636
logWatchUnlink(filePath)
3737
remember.forget(group, filePath)
3838
}
@@ -43,40 +43,15 @@ const handleWatchUnlink = (group, filePath) => {
4343

4444
task('clean:cache', () => cache.clearAll())
4545

46-
task('clean:docs:schema', cb => {
47-
rimraf(paths.packages('ability-attributes', 'src/schema.ts'), cb)
48-
})
49-
50-
task('clean:docs:component-menu', cb => {
51-
rimraf(paths.docsSrc('componentMenu.json'), cb)
52-
})
53-
54-
task('clean:docs:component-menu-behaviors', cb => {
55-
rimraf(paths.docsSrc('behaviorMenu.json'), cb)
56-
})
57-
58-
task('clean:docs:dist', cb => {
59-
rimraf(paths.docsDist(), cb)
60-
})
61-
62-
task('clean:docs:example-menus', cb => {
63-
rimraf(paths.docsSrc('exampleMenus'), cb)
64-
})
65-
66-
task('clean:docs:example-sources', cb => {
67-
rimraf(paths.docsSrc('exampleSources'), cb)
68-
})
69-
70-
task(
71-
'clean:docs',
72-
parallel(
73-
'clean:docs:component-menu',
74-
'clean:docs:component-menu-behaviors',
75-
'clean:docs:dist',
76-
'clean:docs:schema',
77-
'clean:docs:example-menus',
78-
'clean:docs:example-sources',
79-
),
46+
task('clean:docs', () =>
47+
del([
48+
paths.packages('ability-attributes/src/schema.ts'),
49+
paths.docsSrc('componentMenu.json'),
50+
paths.docsSrc('behaviorMenu.json'),
51+
paths.docsDist(),
52+
paths.docsSrc('exampleMenus'),
53+
paths.docsSrc('exampleSources'),
54+
]),
8055
)
8156

8257
// ----------------------------------------
@@ -220,7 +195,7 @@ task('serve:docs:hot', async () => {
220195
noInfo: true, // must be quite for hot middleware to show overlay
221196
lazy: false,
222197
stats: config.compiler_stats,
223-
}),
198+
} as WebpackDevMiddleware.Options),
224199
)
225200
.use(WebpackHotMiddleware(compiler)),
226201
)
@@ -232,13 +207,26 @@ task('serve:docs:stop', () => forceClose(server))
232207
// Watch
233208
// ----------------------------------------
234209

235-
task('watch:docs', cb => {
210+
task('watch:docs:component-info', cb => {
236211
// rebuild component info
237212
watch(componentsSrc, series('build:docs:component-info'))
238213
.on('add', logWatchAdd)
239214
.on('change', logWatchChange)
240215
.on('unlink', logWatchUnlink)
241216

217+
cb()
218+
})
219+
220+
task('watch:docs:component-menu-behaviors', cb => {
221+
watch(behaviorSrc, series('build:docs:component-menu-behaviors'))
222+
.on('add', logWatchAdd)
223+
.on('change', logWatchChange)
224+
.on('unlink', filePath => handleWatchUnlink('component-menu-behaviors', filePath))
225+
226+
cb()
227+
})
228+
229+
task('watch:docs:other', cb => {
242230
watch(schemaSrc, series('build:docs:schema')).on('change', logWatchChange)
243231

244232
// rebuild example menus
@@ -261,11 +249,6 @@ task('watch:docs', cb => {
261249
} catch (e) {}
262250
})
263251

264-
watch(behaviorSrc, series('build:docs:component-menu-behaviors'))
265-
.on('add', logWatchAdd)
266-
.on('change', logWatchChange)
267-
.on('unlink', filePath => handleWatchUnlink('component-menu-behaviors', filePath))
268-
269252
// rebuild images
270253
watch(`${config.paths.docsSrc()}/**/*.{png,jpg,gif}`, series('build:docs:images'))
271254
.on('add', logWatchAdd)
@@ -275,6 +258,11 @@ task('watch:docs', cb => {
275258
cb()
276259
})
277260

261+
task(
262+
'watch:docs',
263+
series('watch:docs:component-info', 'watch:docs:component-menu-behaviors', 'watch:docs:other'),
264+
)
265+
278266
// ----------------------------------------
279267
// Default
280268
// ----------------------------------------

build/gulp/tasks/perf.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { series, task } from 'gulp'
44
import _ from 'lodash'
55
import ProgressBar from 'progress'
66
import puppeteer from 'puppeteer'
7-
import rimraf from 'rimraf'
7+
import del from 'del'
88
import { argv } from 'yargs'
99
import markdownTable from 'markdown-table'
1010

@@ -109,9 +109,7 @@ const createMarkdownTable = (
109109
])
110110
}
111111

112-
task('perf:clean', cb => {
113-
rimraf(paths.perfDist(), cb)
114-
})
112+
task('perf:clean', () => del(paths.perfDist()))
115113

116114
task('perf:build', cb => {
117115
webpackPlugin(require('../../../build/webpack.config.perf').default, cb)

build/gulp/tasks/test-dependencies/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import config from '../../../../config'
99
const { paths } = config
1010

1111
const prefix = (argv.prefix as string) || ''
12-
const packageName = (argv.package as string) || 'react'
12+
const packageName = config.package
1313

1414
/**
1515
* Lists runtime dependencies (by crawling the actual code) of the requested Fluent UI package.

build/gulp/tasks/test-e2e.ts

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { task, series } from 'gulp'
22
import * as yargs from 'yargs'
3-
import rimraf from 'rimraf'
3+
import del from 'del'
44
import config from '../../../config'
55
import webpackPlugin from '../plugins/gulp-webpack'
66

@@ -15,9 +15,7 @@ const argv = yargs
1515
.option('testNamePattern', { alias: 't' })
1616
.option('testFilePattern', { alias: 'F' }).argv
1717

18-
task('test:e2e:clean', cb => {
19-
rimraf(paths.e2eDist(), cb)
20-
})
18+
task('test:e2e:clean', () => del(paths.e2eDist()))
2119

2220
task('test:e2e:build', cb => {
2321
webpackPlugin(require('../../../build/webpack.config.e2e').default, cb)

build/gulp/tasks/test-projects.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from 'path'
66
import portfinder from 'portfinder'
77
import puppeteer from 'puppeteer'
88
import sh from '../sh'
9-
import rimraf from 'rimraf'
9+
import del from 'del'
1010

1111
import config from '../../../config'
1212
import tmp from 'tmp'
@@ -87,7 +87,7 @@ const createReactApp = async (atTempDirectory: string, appName: string): Promise
8787
await runIn(tempUtilProjectPath)(`yarn create-react-app ${appProjectPath} --typescript`)
8888
} finally {
8989
// remove temp util directory
90-
rimraf.sync(tempUtilProjectPath)
90+
del.sync(tempUtilProjectPath, { force: true })
9191
}
9292

9393
return appProjectPath

build/gulp/tasks/test-unit.ts

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
import { parallel, series, task } from 'gulp'
22
import yargs from 'yargs'
33

4-
import sh from '../sh'
54
import jest, { JestPluginConfig } from '../plugins/gulp-jest'
65

6+
import config from '../../../config'
7+
78
const argv = yargs
89
.option('runInBand', {})
910
.option('maxWorkers', {})
@@ -19,15 +20,9 @@ const jestConfigFromArgv: Partial<JestPluginConfig> = {
1920
testFilePattern: argv.testFilePattern as string,
2021
}
2122

22-
task('test:jest:pre', () => sh('yarn satisfied'))
23-
24-
task(
25-
'test:jest:setup',
26-
series(
27-
'test:jest:pre',
28-
parallel('build:docs:component-info', 'build:docs:component-menu-behaviors'),
29-
),
30-
)
23+
if (process.env.CI) {
24+
jestConfigFromArgv.maxWorkers = 2
25+
}
3126

3227
task(
3328
'test:jest',
@@ -51,5 +46,18 @@ task(
5146
// Tests
5247
// ----------------------------------------
5348

54-
task('test', series('test:jest:setup', 'test:jest'))
55-
task('test:watch', series('test:jest:setup', parallel('test:jest:watch', 'watch:docs')))
49+
if (config.isRoot) {
50+
// If running at root, define test and test:watch to build doc-related pre-reqs
51+
task(
52+
'test:jest:setup',
53+
parallel('build:docs:component-info', 'build:docs:component-menu-behaviors'),
54+
)
55+
task('test', series('test:jest:setup', 'test:jest'))
56+
task(
57+
'test:watch',
58+
series('test:jest:setup', parallel('test:jest:watch', 'watch:docs:component-info')),
59+
)
60+
} else {
61+
task('test', series('test:jest'))
62+
task('test:watch', series('test:jest', 'test:jest:watch'))
63+
}

0 commit comments

Comments
 (0)