-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
7 changed files
with
268 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
// babel-preset-taro 更多选项和默认值: | ||
// https://github.com/NervJS/taro/blob/next/packages/babel-preset-taro/README.md | ||
module.exports = { | ||
presets: [ | ||
[ | ||
'taro', | ||
{ | ||
framework: 'react', | ||
ts: 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import path from 'path' | ||
import WebpackChain from 'webpack-chain' | ||
import { TaroProvidePlugin } from '../dist/plugins' | ||
import { IProjectConfig } from '@tarojs/taro/types/compile' | ||
|
||
const config: IProjectConfig = { | ||
projectName: 'test', | ||
date: '2020-2-22', | ||
designWidth: 750, | ||
deviceRatio: { 750: 1 }, | ||
sourceRoot: 'test/src', | ||
outputRoot: 'test/dist', | ||
framework: 'react', | ||
alias: { | ||
'@tarojsx/polyfill': path.resolve(__dirname, '..'), | ||
}, | ||
mini: { | ||
webpackChain(chain: WebpackChain) { | ||
chain.optimization.sideEffects(false) | ||
chain.plugin('taroProvidePlugin').use(TaroProvidePlugin, [['default', 'Intl']]) | ||
}, | ||
}, | ||
} | ||
|
||
export default function (merge) { | ||
if (process.env.NODE_ENV === 'development') { | ||
return merge({}, config, { env: { NODE_ENV: '"development"' } }) | ||
} | ||
return merge({}, config, { env: { NODE_ENV: '"production"' } }) | ||
} |
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,31 @@ | ||
{ | ||
"miniprogramRoot": "test/dist/", | ||
"projectname": "tarojsx-polyfill-test", | ||
"appid": "touristappid", | ||
"compileType": "miniprogram", | ||
"simulatorType": "wechat", | ||
"simulatorPluginLibVersion": {}, | ||
"setting": { | ||
"urlCheck": false, | ||
"es6": false, | ||
"postcss": false, | ||
"preloadBackgroundData": false, | ||
"minified": false, | ||
"newFeature": true, | ||
"coverView": true, | ||
"autoAudits": false, | ||
"showShadowRootInWxmlPanel": true, | ||
"scopeDataCheck": false, | ||
"checkInvalidKey": true, | ||
"checkSiteMap": false, | ||
"uploadWithSourceMap": true, | ||
"babelSetting": { | ||
"ignore": [], | ||
"disablePlugins": [], | ||
"outputPath": "" | ||
}, | ||
"useCompilerModule": false, | ||
"userConfirmedUseCompilerModuleSwitch": false | ||
}, | ||
"condition": {} | ||
} |
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,5 @@ | ||
import { AppConfig } from '@tarojs/taro' | ||
|
||
export default { | ||
pages: ['pages/index'], | ||
} as AppConfig |
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,7 @@ | ||
import React from 'react' | ||
|
||
export default class App extends React.Component { | ||
render() { | ||
return this.props.children | ||
} | ||
} |
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,24 @@ | ||
import React from 'react' | ||
import Taro from '@tarojs/taro' | ||
|
||
const polyfills = { | ||
fetch: fetch, | ||
'window.fetch': window.fetch, | ||
Intl: Intl, | ||
'window.Intl': window.Intl, | ||
navigator: navigator, | ||
'window.navigator': window.navigator, | ||
'performance.now': performance.now, | ||
'window.performance.now': window.performance.now, | ||
requestAnimationFrame: requestAnimationFrame, | ||
'window.requestAnimationFrame': window.requestAnimationFrame, | ||
cancelAnimationFrame: cancelAnimationFrame, | ||
'window.cancelAnimationFrame': window.cancelAnimationFrame, | ||
} | ||
|
||
export default () => { | ||
Taro.useDidShow(() => { | ||
Taro.getApp().globalData = polyfills | ||
}) | ||
return <view>testing {Object.keys(polyfills).length} polyfills...</view> | ||
} |
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,158 @@ | ||
/// <reference types="@minapp/wx" /> | ||
|
||
import path from 'path' | ||
import automator from 'miniprogram-automator' | ||
import MiniProgram from 'miniprogram-automator/out/MiniProgram' | ||
import Page from 'miniprogram-automator/out/Page' | ||
|
||
const cwd = path.resolve(__dirname, '..') | ||
|
||
jest.setTimeout(10000) | ||
|
||
describe('weapp', () => { | ||
let miniProgram: MiniProgram | ||
let page: Page | ||
|
||
beforeAll(async () => { | ||
miniProgram = await automator.launch({ | ||
projectPath: cwd, | ||
}) | ||
page = await miniProgram.currentPage() | ||
page.waitFor(500) | ||
}, 30000) | ||
|
||
afterAll(async () => { | ||
miniProgram && (await miniProgram.close()) | ||
}) | ||
|
||
describe('polyfill', () => { | ||
it('have 6 polyfills and 6 window fields', async () => { | ||
let res = await miniProgram.evaluate(() => Object.keys(getApp()['globalData'])) | ||
expect(res.length).toBe(6 * 2) | ||
}) | ||
}) | ||
|
||
describe('fetch', () => { | ||
it('has fetch', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let { fetch, 'window.fetch': $fetch } = getApp()['globalData'] | ||
return { | ||
same: fetch === $fetch, | ||
type: typeof fetch, | ||
} | ||
}) | ||
expect(res.same).toBe(true) | ||
expect(res.type).toBe('function') | ||
}) | ||
|
||
it('fetch website', async () => { | ||
let res = await miniProgram.evaluate(() => | ||
(async () => { | ||
const fetch: Window['fetch'] = getApp()['globalData'].fetch | ||
return await fetch('https://servicewechat.com') | ||
})() | ||
) | ||
expect(res.status).toBe(200) | ||
}) | ||
}) | ||
|
||
describe('Intl', () => { | ||
it('has Intl', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let { Intl, 'window.Intl': $Intl } = getApp()['globalData'] | ||
return { | ||
Intl, | ||
$Intl, | ||
} | ||
}) | ||
expect(res.Intl).toBeTruthy() | ||
expect(res.Intl).toEqual(res.$Intl) | ||
}) | ||
}) | ||
|
||
describe('navigator', () => { | ||
it('has navigator', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let { navigator, 'window.navigator': $navigator } = getApp()['globalData'] | ||
return { | ||
navigator, | ||
$navigator, | ||
} | ||
}) | ||
expect(res.navigator).toBeTruthy() | ||
expect(res.navigator).toEqual(res.$navigator) | ||
}) | ||
|
||
it('is Taro product', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let navigator: Navigator = getApp()['globalData'].navigator | ||
return navigator.product | ||
}) | ||
expect(res).toBe('Taro') | ||
}) | ||
}) | ||
|
||
describe('performance.now', () => { | ||
it('has performance.now', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let { 'performance.now': now, 'window.performance.now': $now } = getApp()['globalData'] | ||
return { | ||
same: now === $now, | ||
type: typeof now, | ||
} | ||
}) | ||
expect(res.same).toBe(true) | ||
expect(res.type).toBe('function') | ||
}) | ||
|
||
it('return positive number', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let now: Window['performance']['now'] = getApp()['globalData']['performance.now'] | ||
return now() | ||
}) | ||
expect(res).toBeGreaterThan(0) | ||
}) | ||
}) | ||
|
||
describe('raf', () => { | ||
it('has raf', async () => { | ||
let res = await miniProgram.evaluate(() => { | ||
let { | ||
requestAnimationFrame, | ||
cancelAnimationFrame, | ||
'window.requestAnimationFrame': $requestAnimationFrame, | ||
'window.cancelAnimationFrame': $cancelAnimationFrame, | ||
} = getApp()['globalData'] | ||
|
||
return { | ||
same: | ||
requestAnimationFrame === $requestAnimationFrame && | ||
cancelAnimationFrame === $cancelAnimationFrame, | ||
type: typeof requestAnimationFrame, | ||
type2: typeof cancelAnimationFrame, | ||
} | ||
}) | ||
expect(res.same).toBe(true) | ||
expect(res.type).toBe('function') | ||
expect(res.type2).toBe('function') | ||
}) | ||
|
||
it('invoke callback', async () => { | ||
let res = await miniProgram.evaluate(() => | ||
(async () => { | ||
let data = getApp()['globalData'] | ||
let requestAnimationFrame: Window['requestAnimationFrame'] = data.requestAnimationFrame | ||
let cancelAnimationFrame: Window['cancelAnimationFrame'] = data.cancelAnimationFrame | ||
|
||
return await new Promise((resolve) => { | ||
let timer = requestAnimationFrame(() => { | ||
cancelAnimationFrame(timer) | ||
resolve(true) | ||
}) | ||
}) | ||
})() | ||
) | ||
expect(res).toBe(true) | ||
}) | ||
}) | ||
}) |