Permalink
Browse files

API and test improvements (#58)

* wip

* API improvements

* Basic testing

* Restructure

* wip

* Improve build & API

* Introduce e2e tests

* Test with auto prefetching
  • Loading branch information...
mgechev committed Jun 16, 2018
1 parent 66de266 commit 51258ad039ef00778fb49e163de25017271f50d6
Showing with 3,358 additions and 6,764 deletions.
  1. +4 −1 .travis.yml
  2. +3 −2 infra/build.ts
  3. +1 −1 infra/install.ts
  4. +13 −0 infra/pretest.ts
  5. +32 −0 infra/test.ts
  6. +6 −0 jest-puppeteer.config.js
  7. +18 −0 jest.config.js
  8. +1,869 −131 package-lock.json
  9. +12 −22 package.json
  10. +45 −2,037 packages/ga/package-lock.json
  11. +2 −2 packages/ga/package.json
  12. +3 −1 packages/ga/src/client.ts
  13. 0 packages/ga/{__tests__ → test}/normalize.spec.ts
  14. +0 −42 packages/parser/__tests__/detect.spec.ts
  15. +0 −9 packages/parser/__tests__/fixtures/react-app-ts/src/App.test.tsx
  16. +338 −2,576 packages/parser/package-lock.json
  17. +3 −4 packages/parser/package.json
  18. +2 −2 packages/parser/{__tests__ → test}/angular.spec.ts
  19. +34 −0 packages/parser/test/detect.spec.ts
  20. 0 packages/parser/{__tests__ → test}/fixtures/angular/.angular-cli.json
  21. +8 −8 packages/parser/{__tests__ → test}/fixtures/angular/package-lock.json
  22. 0 packages/parser/{__tests__ → test}/fixtures/angular/package.json
  23. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app-routing.module.ts
  24. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app.component.css
  25. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app.component.html
  26. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app.component.spec.ts
  27. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app.component.ts
  28. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/app.module.ts
  29. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/bar/bar.component.ts
  30. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/bar/bar.module.ts
  31. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/foo/foo-routing.module.ts
  32. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/foo/foo.component.ts
  33. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/app/foo/foo.module.ts
  34. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/environments/environment.prod.ts
  35. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/environments/environment.ts
  36. BIN packages/parser/{__tests__ → test}/fixtures/angular/src/favicon.ico
  37. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/index.html
  38. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/main.ts
  39. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/polyfills.ts
  40. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/styles.css
  41. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/test.ts
  42. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/tsconfig.app.json
  43. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/tsconfig.spec.json
  44. 0 packages/parser/{__tests__ → test}/fixtures/angular/src/typings.d.ts
  45. 0 packages/parser/{__tests__ → test}/fixtures/angular/tsconfig.json
  46. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/.gitignore
  47. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/.prettierrc
  48. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/LICENSE
  49. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/README.md
  50. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/gatsby-browser.js
  51. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/gatsby-config.js
  52. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/gatsby-node.js
  53. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/gatsby-ssr.js
  54. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/package-lock.json
  55. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/package.json
  56. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/components/header.js
  57. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/layouts/index.css
  58. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/layouts/index.js
  59. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/pages/404.js
  60. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/pages/index.js
  61. 0 packages/parser/{__tests__ → test}/fixtures/gatsby/src/pages/page-2.js
  62. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/.gitignore
  63. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/README.md
  64. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/package.json
  65. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/.babelrc
  66. BIN packages/parser/{__tests__ → test}/fixtures/preact-app/src/assets/favicon.ico
  67. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/components/app.js
  68. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/components/header/index.js
  69. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/components/header/style.css
  70. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/components/info.js
  71. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/index.js
  72. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/manifest.json
  73. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/routes/about/index.js
  74. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/routes/home/index.js
  75. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/routes/home/style.css
  76. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/routes/profile/index.js
  77. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/routes/profile/style.css
  78. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/style/index.css
  79. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/tests/__mocks__/browserMocks.js
  80. 0 packages/parser/{__tests__ → test}/fixtures/preact-app/src/tests/header.test.js
  81. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/.gitignore
  82. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/README.md
  83. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/images.d.ts
  84. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/package-lock.json
  85. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/package.json
  86. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/public/index.html
  87. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/App.css
  88. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/App.tsx
  89. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/LazyRoute.tsx
  90. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/index.css
  91. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/index.tsx
  92. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/intro/Intro.tsx
  93. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/logo.svg
  94. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/main/Main.tsx
  95. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/main/kid/Kid.tsx
  96. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/main/parent/Parent.tsx
  97. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/src/registerServiceWorker.ts
  98. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/tsconfig.json
  99. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/tsconfig.test.json
  100. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/tslint.json
  101. 0 packages/parser/{__tests__ → test}/fixtures/react-app-ts/yarn.lock
  102. 0 packages/parser/{__tests__ → test}/fixtures/react-app/.gitignore
  103. 0 packages/parser/{__tests__ → test}/fixtures/react-app/README.md
  104. 0 packages/parser/{__tests__ → test}/fixtures/react-app/package-lock.json
  105. 0 packages/parser/{__tests__ → test}/fixtures/react-app/package.json
  106. BIN packages/parser/{__tests__ → test}/fixtures/react-app/public/favicon.ico
  107. 0 packages/parser/{__tests__ → test}/fixtures/react-app/public/index.html
  108. 0 packages/parser/{__tests__ → test}/fixtures/react-app/public/manifest.json
  109. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/App.css
  110. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/App.jsx
  111. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/LazyRoute.jsx
  112. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/index.css
  113. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/index.js
  114. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/intro/Intro.jsx
  115. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/logo.svg
  116. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/main/Main.jsx
  117. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/main/kid/Kid.jsx
  118. 0 packages/parser/{__tests__ → test}/fixtures/react-app/src/main/parent/Parent.jsx
  119. 0 packages/parser/{__tests__ → test}/fixtures/react-app/yarn.lock
  120. 0 packages/parser/{__tests__ → test}/fixtures/unknown/package.json
  121. +4 −4 packages/parser/{__tests__ → test}/parser.spec.ts
  122. +3 −3 packages/parser/{__tests__ → test}/preact-jsx.spec.ts
  123. +3 −3 packages/parser/{__tests__ → test}/react-jsx.spec.ts
  124. +3 −3 packages/parser/{__tests__ → test}/react-tsx.spec.ts
  125. +30 −11 packages/webpack/README.md
  126. +0 −49 packages/webpack/__tests__/runtime.spec.ts
  127. +1 −1 packages/webpack/index.ts
  128. +284 −1,605 packages/webpack/package-lock.json
  129. +9 −5 packages/webpack/package.json
  130. +2 −2 packages/webpack/src/declarations.ts
  131. +0 −1 packages/webpack/src/default-route-provider.ts
  132. +19 −23 packages/webpack/src/{guess.ts → guess-webpack.ts}
  133. +47 −15 packages/webpack/src/{prefetch.ts → prefetch-plugin.ts}
  134. +0 −5 packages/webpack/src/runtime.tpl
  135. +0 −173 packages/webpack/src/runtime.ts
  136. +5 −0 packages/webpack/src/runtime/guess.tpl
  137. +140 −0 packages/webpack/src/runtime/guess.ts
  138. +5 −0 packages/webpack/src/runtime/runtime.tpl
  139. +77 −0 packages/webpack/src/runtime/runtime.ts
  140. +35 −0 packages/webpack/test/e2e/delegate.spec.ts
  141. +47 −0 packages/webpack/test/e2e/prefetch.spec.ts
  142. +12 −0 packages/webpack/test/fixtures/delegate/index.html
  143. +1 −0 packages/webpack/test/fixtures/delegate/index.js
  144. +29 −0 packages/webpack/test/fixtures/delegate/webpack.config.js
  145. +1 −0 packages/webpack/test/fixtures/prefetch/about.js
  146. +1 −0 packages/webpack/test/fixtures/prefetch/contact.js
  147. +1 −0 packages/webpack/test/fixtures/prefetch/home.js
  148. +15 −0 packages/webpack/test/fixtures/prefetch/index.html
  149. +18 −0 packages/webpack/test/fixtures/prefetch/index.js
  150. +62 −0 packages/webpack/test/fixtures/prefetch/webpack.config.js
  151. +2 −2 packages/webpack/{__tests__ → test/unit}/compress.spec.ts
  152. +71 −0 packages/webpack/test/unit/runtime.spec.ts
  153. +1 −1 packages/webpack/tsconfig.json
  154. +36 −19 packages/webpack/webpack.config.js
  155. +1 −1 tsconfig.json
@@ -1,9 +1,12 @@
language: node_js
node_js: stable
os: linux
sudo: required
install: npm i
script: npm run test:ci
script:
- npm run build
- npm run test:ci
git:
depth: 5
@@ -32,13 +32,14 @@ const publish = (path: string) => {
const packageNames = new Set(['guess-ga', 'guess-parser', 'guess-webpack']);
const build = (hook = (path: string) => {}) => {
const cwd = process.cwd();
const Packages = ['ga', 'parser', 'webpack'];
const PackagesDir = join(process.cwd(), 'packages');
const PackagesDir = join(cwd, 'packages');
const config = JSON.parse(fs.readFileSync(join('config.json')).toString());
for (const p of Packages) {
const path = join(PackagesDir, p);
console.log(execSync(`cd ${path} && rm -rf dist && ./node_modules/.bin/webpack`).toString());
console.log(execSync(`cd ${path} && rm -rf dist && ${cwd}/node_modules/.bin/webpack .`).toString());
const packageJsonPath = join(path, 'package.json');
const packageJson = JSON.parse(fs.readFileSync(packageJsonPath).toString());
packageJson.version = config.version;
@@ -8,4 +8,4 @@ for (const p of Packages) {
console.log(execSync(`cd ${path} && npm i`).toString());
}
console.log(execSync(`cd ${join(PackagesDir, 'parser', '__tests__', 'fixtures', 'angular')} && npm i`).toString());
console.log(execSync(`cd ${join(PackagesDir, 'parser', 'test', 'fixtures', 'angular')} && npm i`).toString());
@@ -0,0 +1,13 @@
import { readdirSync } from 'fs';
import { join } from 'path';
import { execSync } from 'child_process';
const cwd = process.cwd();
const base = join(cwd, 'packages', 'webpack', 'test', 'fixtures');
readdirSync(base).forEach(dir => {
if (dir === '.' || dir === '..') {
return;
}
execSync(`cd ${join(base, dir)} && rm -rf dist && ${cwd}/node_modules/.bin/webpack`);
});
@@ -0,0 +1,32 @@
import { join } from 'path';
import { spawn } from 'child_process';
import chalk from 'chalk';
const StaticServer = require('static-server');
const port = 5122;
function setupMockServer() {
return new Promise(resolve => {
const server = new StaticServer({
rootPath: join(process.cwd(), 'packages', 'webpack', 'test', 'fixtures'),
port
});
server.start(() => {
console.log(chalk.yellow('Test server started on port', server.port));
resolve(server);
});
});
}
async function main() {
await setupMockServer();
const watch = process.argv.filter(a => a === '--watch');
const jest = spawn(`${process.cwd()}/node_modules/.bin/jest`, watch, { stdio: 'inherit' });
return new Promise<number>(resolve => {
jest.on('exit', code => resolve(code));
jest.on('close', code => resolve(code));
});
}
main().then(code => process.exit(code));
@@ -0,0 +1,6 @@
module.exports = {
launch: {
args: ['--no-sandbox', '--disable-setuid-sandbox'],
headless: true
}
};
@@ -0,0 +1,18 @@
module.exports = {
transform: {
'^.+\\.tsx?$': 'ts-jest'
},
testRegex: '(/test/.*|(\\.|/)(test|spec))\\.(jsx?|tsx?)$',
testPathIgnorePatterns: [
'<rootDir>/packages/detector/test/fixtures',
'<rootDir>/packages/parser/test/fixtures',
'<rootDir>/infra/test.ts',
'<rootDir>/experiments/guess-static-sites/test',
'<rootDir>/packages/webpack/test/fixtures'
],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
preset: '<rootDir>/node_modules/jest-puppeteer',
globals: {
window: {}
}
};
Oops, something went wrong.

0 comments on commit 51258ad

Please sign in to comment.