Skip to content

Commit

Permalink
No dist
Browse files Browse the repository at this point in the history
Compile into lib/ test/ instead.

The reason for this is to support `import from
"browser-monkey/ReactMount"`. The only other way I could find that would
support that was to convert bm to es module. But that seems like it's
own can of worms.
  • Loading branch information
artemave committed Feb 26, 2021
1 parent 8c42624 commit 0129629
Show file tree
Hide file tree
Showing 22 changed files with 55 additions and 133 deletions.
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ module.exports = {
"mocha",
],
ignorePatterns: [
"dist/",
"lib/**/*.js",
"test/**/*.js",
"docs/",
"docs-dist/",
],
Expand Down
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
*.orig
/node_modules/
.DS_Store
/dist/
docs-dist/
.exrc
test/**/*.js
test/**/*.js.map
lib/**/*.js
lib/**/*.js.map
index.js*
*Mount.js*
tsconfig.tsbuildinfo
tsconfig.build.tsbuildinfo
4 changes: 2 additions & 2 deletions lib/HyperdomMount.ts → HyperdomMount.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Mount from './Mount'
import extend from 'lowscore/extend'
import hyperdom from 'hyperdom'
import Mount from './lib/Mount'

export default class HyperdomMount extends Mount {
constructor (app: any, options?) {
Expand All @@ -12,7 +13,6 @@ export default class HyperdomMount extends Mount {
if (options && (options.hash || options.url) && options.router) {
options.router.push(options.url || options.hash)
}
const hyperdom = require('hyperdom')
hyperdom.append(testDiv, app, extend({ requestRender: setTimeout }, options))
}
}
4 changes: 2 additions & 2 deletions lib/ReactMount.ts → ReactMount.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import Mount from './Mount'
import ReactDOM from 'react-dom'
import Mount from './lib/Mount'

export default class ReactMount extends Mount {
public constructor (vdom: any) {
super()
const div = this.containerElement()

const ReactDOM = require('react-dom')
ReactDOM.render(vdom, div)
}
}
10 changes: 8 additions & 2 deletions docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,21 @@ There are a couple of shortcuts for doing this for particular frameworks. Otherw

### React

Assumes `react-dom` module is installed.

```js
import {ReactMount, Query} from 'browser-monkey'
import {Query} from 'browser-monkey'
import ReactMount from 'browser-monkey/ReactMount'
const mount = new ReactMount(React.createElement(YourReactApp, {}, null))
```

### Hyperdom

Assumes `hyperdom` module is installed.

```js
import {HyperdomMount, Query} from 'browser-monkey'
import {Query} from 'browser-monkey'
import HyperdomMount from 'browser-monkey/HyperdomMount'
const mount = new HyperdomMount(new YourHyperdomApp())
```

Expand Down
3 changes: 2 additions & 1 deletion docs/quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ Now create a test file: `test/appSpec.js`
For simplicity we will create our react application in the test file.

```js
const {ReactMount, Query} = require('browser-monkey')
const {Query} = require('browser-monkey')
const ReactMount = require('browser-monkey/ReactMount')
const React = require('react')

class App extends React.Component {
Expand Down
2 changes: 0 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import {Query} from './lib/Query'
import IFrameMount from './lib/IFrameMount'
import Mount from './lib/Mount'
import ReactMount from './lib/ReactMount'
import * as matchers from './lib/matchers'

export {
Query,
IFrameMount,
Mount,
ReactMount,
matchers,
}
2 changes: 1 addition & 1 deletion lib/createTestDiv.js → lib/createTestDiv.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
let div

module.exports = function () {
export default function createTestDiv () {
if (div && div.parentNode) {
div.parentNode.removeChild(div)
}
Expand Down
2 changes: 1 addition & 1 deletion lib/inputSelectors.js → lib/inputSelectors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const settable =
'input[type=range],' +
'textarea'

module.exports = {
export default {
settable,
gettable: 'input,textarea',
}
2 changes: 1 addition & 1 deletion lib/normaliseText.js → lib/normaliseText.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = function normaliseText (text) {
export default function normaliseText (text) {
return text.replace(/ +/g, ' ').replace(/ *\r?\n */g, '\n').trim()
}
7 changes: 4 additions & 3 deletions lib/polyfills.js → lib/polyfills.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports.MouseEvent = (function () {
export const MouseEvent = (function () {
try {
new MouseEvent('click') // eslint-disable-line
return MouseEvent // eslint-disable-line
Expand All @@ -8,7 +8,7 @@ module.exports.MouseEvent = (function () {

const MouseEventPolyfill = function (eventType, params) {
params = params || { bubbles: false, cancelable: false }
var mouseEvent = document.createEvent('MouseEvent')
const mouseEvent = document.createEvent('MouseEvent')
mouseEvent.initMouseEvent(
eventType,
params.bubbles,
Expand Down Expand Up @@ -36,7 +36,7 @@ module.exports.MouseEvent = (function () {
})()

// based on https://github.com/lifaon74/events-polyfill/blob/5ccca4002aa07f16ed1c298145f20c06d3544a29/src/constructors/KeyboardEvent.js
module.exports.KeyboardEvent = (function () {
export const KeyboardEvent = (function () {
try {
new KeyboardEvent('keyup') // eslint-disable-line
return KeyboardEvent // eslint-disable-line
Expand All @@ -56,6 +56,7 @@ module.exports.KeyboardEvent = (function () {
].filter(Boolean).join(' ')

const keyEvent = document.createEvent('KeyboardEvent')
// @ts-ignore
keyEvent.initKeyboardEvent(
eventType,
!!params.bubbles,
Expand Down
2 changes: 1 addition & 1 deletion lib/reloadButton.js → lib/reloadButton.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const hobostyle = require('hobostyle')
const extend = require('lowscore/extend')

module.exports = function reloadButton (_options) {
export default function reloadButton (_options) {
const options = extend({
style: true,
class: 'browser-monkey-reload'
Expand Down
9 changes: 0 additions & 9 deletions lib/setTestUrl.js

This file was deleted.

26 changes: 0 additions & 26 deletions lib/stubBrowser.js

This file was deleted.

9 changes: 4 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
"name": "browser-monkey",
"version": "3.0.0-beta.8",
"description": "reliable dom testing",
"main": "dist/index.js",
"files": [
"dist/*",
"lib/*",
"test/*",
"index.ts"
"index.*",
"*Mount.*"
],
"scripts": {
"test": "yarn test-electron-mocha && eslint .",
"test-karma": "karma start --single-run",
"test-electron-mocha": "yarn electron-mocha test/**/*Spec.{js,ts}",
"test-electron-mocha": "yarn electron-mocha test/**/*Spec.ts",
"electron-mocha": "electron-mocha --disable-site-isolation-trials --full-trace --color --main electron/foreignIframe.js -r ts-node/register --renderer",
"mocha": "mocha -r test/register.js",
"prepare": "tsc -p tsconfig.build.json",
Expand All @@ -36,7 +35,7 @@
"babel-loader": "^8.1.0",
"chai": "4.2.0",
"codesandbox-example-links": "^1.1.0",
"electron": "11.0.3",
"electron": "12.0.0-beta.30",
"electron-mocha": "^10.0.0",
"eslint": "^7.12.1",
"eslint-config-standard": "^16.0.1",
Expand Down
18 changes: 0 additions & 18 deletions react.js

This file was deleted.

2 changes: 1 addition & 1 deletion test/assemblies/DomAssembly.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* global location */

const createTestDiv = require('../../lib/createTestDiv')
import createTestDiv from '../../lib/createTestDiv'
const pathUtils = require('path')
import retry from '../../lib/retry'
const { expect } = require('chai')
Expand Down
33 changes: 0 additions & 33 deletions test/mountReactSpec.tsx

This file was deleted.

4 changes: 2 additions & 2 deletions test/mountSpec.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Query} from '../lib/Query'
import {DomAssembly} from './assemblies/DomAssembly'
import ReactMount from '../lib/ReactMount'
import ReactMount from '../ReactMount'
import IFrameMount from '../lib/IFrameMount'
import Mount from '../lib/Mount'
import ReactApp from './app/react'
import React from 'react'
import HyperdomMount from '../lib/HyperdomMount'
import HyperdomMount from '../HyperdomMount'
import HyperdomApp from './app/hyperdom'

describe('mount', () => {
Expand Down
5 changes: 1 addition & 4 deletions tsconfig.build.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
{
"extends": "./tsconfig.json",
"files": [
"index.ts"
],
"include": ["lib/**/*"],
"include": ["lib/**/*.tsx?"],
"compilerOptions": {
"lib": ["es2015", "dom"],
"target": "ES5"
Expand Down
14 changes: 6 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@
"lib": ["dom"],
"noImplicitAny": false,
"esModuleInterop": true,
"rootDir": ".",
"outDir": "./dist",
"allowJs": true,
"target": "ES6",
"module": "CommonJS",
"jsx": "react",
"jsxFactory": "hyperdom.jsx",
"sourceMap": true
},
"exclude": [
"node_modules",
"docs",
"dist"
]
"files": [
"index.ts",
"HyperdomMount.ts",
"ReactMount.ts"
],
"include": ["lib/**/*.tsx?", "test/**/*.tsx?"]
}
18 changes: 9 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1034,10 +1034,10 @@
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.6.tgz#146d3da57b3c636cc0d1769396ce1cfa8991147f"
integrity sha512-6QlRuqsQ/Ox/aJEQWBEJG7A9+u7oSYl3mem/K8IzxXG/kAGbV1YPD9Bg9Zw3vyxC/YP+zONKwy8hGkSt1jxFMw==

"@types/node@^12.0.12":
version "12.19.3"
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.19.3.tgz#a6e252973214079155f749e8bef99cc80af182fa"
integrity sha512-8Jduo8wvvwDzEVJCOvS/G6sgilOLvvhn1eMmK3TW8/T217O7u1jdrK6ImKLv80tVryaPSVeKu6sjDEiFjd4/eg==
"@types/node@^14.6.2":
version "14.14.31"
resolved "https://registry.yarnpkg.com/@types/node/-/node-14.14.31.tgz#72286bd33d137aa0d152d47ec7c1762563d34055"
integrity sha512-vFHy/ezP5qI0rFgJ7aQnjDXwAMrG0KqqIH7tQG5PPv3BWBayOPIQNBjVc/P6hhdZfMx51REc6tfDNXHUio893g==

"@typescript-eslint/eslint-plugin@^4.6.1":
version "4.6.1"
Expand Down Expand Up @@ -2512,13 +2512,13 @@ electron-window@^0.8.0:
dependencies:
is-electron-renderer "^2.0.0"

electron@11.0.3:
version "11.0.3"
resolved "https://registry.yarnpkg.com/electron/-/electron-11.0.3.tgz#c29eaacda38ce561890e59906ca5f507c72b3ec4"
integrity sha512-nNfbLi7Q1xfJXOEO2adck5TS6asY4Jxc332E4Te8XfQ9hcaC3GiCdeEqk9FndNCwxhJA5Lr9jfSGRTwWebFa/w==
electron@12.0.0-beta.30:
version "12.0.0-beta.30"
resolved "https://registry.yarnpkg.com/electron/-/electron-12.0.0-beta.30.tgz#4e60a0fcab9f0fb0f81896184572102fa5f0c24a"
integrity sha512-Ibe4R6ZlTOGjzmi2R/Y7Uv6wziLNIPVnBoQYcHBAgkLk7mgTULa/fu72x/XPOwVPNBhSA1p/pidZytbcCEs5Yg==
dependencies:
"@electron/get" "^1.0.1"
"@types/node" "^12.0.12"
"@types/node" "^14.6.2"
extract-zip "^1.0.3"

email-addresses@^3.0.1:
Expand Down

0 comments on commit 0129629

Please sign in to comment.