-
Notifications
You must be signed in to change notification settings - Fork 5
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
41 changed files
with
2,810 additions
and
168 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 @@ | ||
module.exports = require('babel-preset-enact'); |
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,17 @@ | ||
/* | ||
* corejs-proxy.js | ||
* | ||
* For babel-preset-env with "useBuiltin":"entry", it requires that the | ||
* require('core-js') expression be at the module level for it to | ||
* be transpiled into the individual core-js polyfills. This proxy module | ||
* allows for dynamic core-js usage while still using the individual feature | ||
* transforms. | ||
*/ | ||
|
||
// Apply stable core-js polyfills | ||
require('core-js/stable'); | ||
|
||
// Manually set global._babelPolyfill as a flag to avoid multiple loading. | ||
// Uses 'babelPolyfill' name for historical meaning and external/backward | ||
// compatibility. | ||
global._babelPolyfill = 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,9 @@ | ||
'use strict'; | ||
const {createHash} = require('crypto'); | ||
|
||
module.exports = env => { | ||
const hash = createHash('md5'); | ||
hash.update(JSON.stringify(env)); | ||
|
||
return hash.digest('hex'); | ||
}; |
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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
<script src="customizations/custom_skin.js"></script> | ||
<link rel="stylesheet" href="customizations/custom_skin.css"> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
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,29 @@ | ||
/* eslint-env node, es6 */ | ||
|
||
const fs = require('fs'); | ||
const path = require('path'); | ||
const dotenv = require('dotenv'); | ||
const {expand} = require('dotenv-expand'); | ||
|
||
// Loads all required .env files in correct order, for a given mode. | ||
// See https://github.com/bkeepers/dotenv#what-other-env-files-can-i-use | ||
module.exports = { | ||
load: function (context) { | ||
const mode = process.env.NODE_ENV || 'development'; | ||
[ | ||
`.env.${mode}.local`, | ||
// Similar to create-react app, don't include `.env.local` for | ||
// `test` environment for test result consistency. | ||
mode !== 'test' && `.env.local`, | ||
`.env.${mode}`, | ||
'.env' | ||
] | ||
.filter(Boolean) | ||
.map(env => path.join(context, env)) | ||
.forEach(env => { | ||
if (fs.existsSync(env)) { | ||
expand(dotenv.config({path: env})); | ||
} | ||
}); | ||
} | ||
}; |
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,12 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<meta http-equiv="x-ua-compatible" content="ie=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no"> | ||
<title><%= htmlWebpackPlugin.options.title %></title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
</body> | ||
</html> |
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,23 @@ | ||
/** | ||
* Portions of this source code file are from create-react-app, used under the | ||
* following MIT license: | ||
* | ||
* Copyright (c) 2014-present, Facebook, Inc. | ||
* https://github.com/facebook/create-react-app | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
const path = require('path'); | ||
const babelJest = require('babel-jest').default; | ||
|
||
module.exports = babelJest.createTransformer({ | ||
extends: path.join(__dirname, '..', 'babel.config.js'), | ||
plugins: [ | ||
require.resolve('@babel/plugin-transform-modules-commonjs'), | ||
require.resolve('babel-plugin-dynamic-import-node') | ||
], | ||
babelrc: false, | ||
configFile: false | ||
}); |
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,14 @@ | ||
'use strict'; | ||
|
||
// This is a custom Jest transformer turning style imports into empty objects. | ||
// http://facebook.github.io/jest/docs/en/webpack.html | ||
|
||
module.exports = { | ||
process() { | ||
return 'module.exports = {};'; | ||
}, | ||
getCacheKey() { | ||
// The output is always the same. | ||
return 'cssTransform'; | ||
} | ||
}; |
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 @@ | ||
'use strict'; | ||
|
||
const path = require('path'); | ||
|
||
// This is a custom Jest transformer turning file imports into filenames. | ||
// http://facebook.github.io/jest/docs/en/webpack.html | ||
|
||
module.exports = { | ||
process(src, filename) { | ||
const assetFilename = JSON.stringify(path.basename(filename)); | ||
return `module.exports = ${assetFilename};`; | ||
} | ||
}; |
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,101 @@ | ||
/** | ||
* Portions of this source code file are from create-react-app, used under the | ||
* following MIT license: | ||
* | ||
* Copyright (c) 2015-present, Facebook, Inc. | ||
* https://github.com/facebook/create-react-app | ||
* | ||
* This source code is licensed under the MIT license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {optionParser: app} = require('@enact/dev-utils'); | ||
|
||
const rbConst = name => | ||
'ILIB_' + | ||
path | ||
.basename(name) | ||
.replace(/[-_\s]/g, '_') | ||
.toUpperCase() + | ||
'_PATH'; | ||
|
||
const iLibDirs = ['node_modules/@enact/i18n/ilib', 'node_modules/ilib', 'ilib']; | ||
const globals = { | ||
__DEV__: true, | ||
ILIB_BASE_PATH: iLibDirs.find(f => fs.existsSync(path.join(app.context, f))) || iLibDirs[1], | ||
ILIB_RESOURCES_PATH: 'resources', | ||
ILIB_CACHE_ID: new Date().getTime() + '', | ||
[rbConst(app.name)]: 'resources' | ||
}; | ||
|
||
for (let t = app.theme; t; t = t.theme) { | ||
const themeRB = path.join(t.path, 'resources'); | ||
globals[rbConst(t.name)] = path.relative(app.context, themeRB).replace(/\\/g, '/'); | ||
} | ||
|
||
const ignorePatterns = [ | ||
// Common directories to ignore | ||
'/node_modules/', | ||
'<rootDir>/(.*/)*coverage/', | ||
'<rootDir>/(.*/)*build/', | ||
'<rootDir>/(.*/)*dist/', | ||
'<rootDir>/(.*/)*docs/', | ||
'<rootDir>/(.*/)*samples/', | ||
'<rootDir>/(.*/)*tests/screenshot/', | ||
'<rootDir>/(.*/)*tests/ui/' | ||
]; | ||
|
||
// Setup env var to signify a testing environment | ||
process.env.BABEL_ENV = 'test'; | ||
process.env.NODE_ENV = 'test'; | ||
process.env.PUBLIC_URL = ''; | ||
process.env.BROWSERSLIST = 'current node'; | ||
|
||
// Load applicable .env files into environment variables. | ||
require('../dotenv').load(app.context); | ||
|
||
// Find any applicable user test setup file | ||
const userSetupFile = ['mjs', 'js', 'jsx', 'ts', 'tsx'] | ||
.map(ext => path.join(app.context, 'src', 'setupTests.' + ext)) | ||
.find(file => fs.existsSync(file)); | ||
|
||
module.exports = { | ||
collectCoverageFrom: ['**/*.{js,jsx,ts,tsx}', '!**/*.d.ts'], | ||
coveragePathIgnorePatterns: ignorePatterns, | ||
setupFiles: [require.resolve('../polyfills')], | ||
setupFilesAfterEnv: [require.resolve('./setupTests'), userSetupFile].filter(Boolean), | ||
testMatch: [ | ||
'<rootDir>/**/__tests__/**/*.{js,jsx,ts,tsx}', | ||
'<rootDir>/**/*.+(spec|test).{js,jsx,ts,tsx}', | ||
'<rootDir>/**/*-specs.{js,jsx,ts,tsx}' | ||
], | ||
testPathIgnorePatterns: ignorePatterns, | ||
testEnvironment: 'jsdom', | ||
testEnvironmentOptions: {pretendToBeVisual: true}, | ||
testURL: 'http://localhost', | ||
transform: { | ||
'^.+\\.(js|jsx|ts|tsx)$': require.resolve('./babelTransform'), | ||
'^.+\\.(css|less|sass|scss)$': require.resolve('./cssTransform.js'), | ||
'^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|less|sass|scss|json)$)': require.resolve('./fileTransform') | ||
}, | ||
transformIgnorePatterns: [ | ||
'[/\\\\]node_modules[/\\\\](?!@enact).+\\.(js|jsx|mjs|cjs|ts|tsx)$', | ||
'^.+\\.module\\.(css|less|sass|scss)$' | ||
], | ||
moduleNameMapper: { | ||
'^.+\\.module\\.(css|less|sass|scss)$': require.resolve('identity-obj-proxy'), | ||
'^@testing-library/jest-dom$': require.resolve('@testing-library/jest-dom'), | ||
'^@testing-library/react$': require.resolve('@testing-library/react'), | ||
'^@testing-library/user-event$': require.resolve('@testing-library/user-event'), | ||
'^react$': require.resolve('react'), | ||
// Backward compatibility for new iLib location with old Enact | ||
'^ilib[/](.*)$': path.join(app.context, globals.ILIB_BASE_PATH, '$1'), | ||
// Backward compatibility for old iLib location with new Enact | ||
'^@enact[/]i18n[/]ilib[/](.*)$': path.join(app.context, globals.ILIB_BASE_PATH, '$1') | ||
}, | ||
moduleFileExtensions: ['js', 'jsx', 'json', 'ts', 'tsx'], | ||
globals, | ||
watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'].map(m => require.resolve(m)), | ||
resetMocks: 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,103 @@ | ||
/* eslint-env jest */ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const {packageRoot} = require('@enact/dev-utils'); | ||
|
||
const filters = [ | ||
'Invalid prop', | ||
'Failed prop type', | ||
'Unknown prop', | ||
'non-boolean attribute', | ||
'Received NaN', | ||
'Invalid value', | ||
'React does not recognize', | ||
'React uses onFocus and onBlur instead of onFocusIn and onFocusOut', | ||
'Invalid event handler property', | ||
'Unknown event handler property', | ||
'Directly setting property `innerHTML` is not permitted', | ||
'The `aria` attribute is reserved for future use in ', | ||
'for a string attribute `is`. If this is expected, cast', | ||
'Invalid DOM property' | ||
]; | ||
const filterExp = new RegExp('(' + filters.join('|') + ')'); | ||
|
||
// Configure proptype & react error checking on the console. | ||
|
||
beforeEach(() => { | ||
jest.spyOn(console, 'warn'); | ||
jest.spyOn(console, 'error'); | ||
}); | ||
|
||
afterEach(() => { | ||
const actual = (console.warn.mock ? console.warn.mock.calls : []) | ||
.concat(console.error.mock ? console.error.mock.calls : []) | ||
.filter(([m]) => filterExp.test(m)); | ||
const expected = 0; | ||
|
||
if (console.warn.mock) { | ||
console.warn.mockRestore(); | ||
} | ||
if (console.error.mock) { | ||
console.error.mockRestore(); | ||
} | ||
|
||
expect(actual).toHaveLength(expected); | ||
}); | ||
|
||
// Set initial resolution to VGA, similar to PhantomJS. | ||
// Will ideally want to use a more modern resolution later. | ||
|
||
global.innerHeight = 640; | ||
global.innerWidth = 480; | ||
|
||
// Support local file sync XHR to support iLib loading. | ||
|
||
const ilibPaths = Object.keys(global).filter(k => /ILIB_[^_]+_PATH/.test(k)); | ||
const pkg = packageRoot(); | ||
const XHR = global.XMLHttpRequest; | ||
class ILibXHR extends XHR { | ||
open(method, url) { | ||
if (ilibPaths.some(p => url.startsWith(global[p]))) { | ||
this.send = () => { | ||
try { | ||
const file = path.join(pkg.path, url.replace(/\//g, path.sep)); | ||
this.fileText = fs.readFileSync(file, {encoding: 'utf8'}); | ||
this.fileStatus = 200; | ||
} catch (e) { | ||
this.fileText = ''; | ||
this.fileStatus = 404; | ||
} | ||
this.dispatchEvent(new global.Event('readystatechange')); | ||
this.dispatchEvent(new global.ProgressEvent('load')); | ||
this.dispatchEvent(new global.ProgressEvent('loadend')); | ||
}; | ||
} else { | ||
return super.open(...arguments); | ||
} | ||
} | ||
get readyState() { | ||
return typeof this.fileStatus !== 'undefined' ? XHR.DONE : super.readyState; | ||
} | ||
get status() { | ||
return typeof this.fileStatus !== 'undefined' ? this.fileStatus : super.status; | ||
} | ||
get responseText() { | ||
return typeof this.fileText !== 'undefined' ? this.fileText : super.responseText; | ||
} | ||
} | ||
global.XMLHttpRequest = ILibXHR; | ||
|
||
beforeEach(() => { | ||
global.Element.prototype.animate = jest.fn().mockImplementation(() => { | ||
const animation = { | ||
onfinish: null, | ||
cancel: () => { | ||
if (animation.onfinish) animation.onfinish(); | ||
}, | ||
finish: () => { | ||
if (animation.onfinish) animation.onfinish(); | ||
} | ||
}; | ||
return animation; | ||
}); | ||
}); |
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,26 @@ | ||
/* eslint no-var: off, no-extend-native: off */ | ||
/* | ||
* polyfills.js | ||
* | ||
* Any polyfills or code required prior to loading the app. | ||
*/ | ||
|
||
if (!global.skipPolyfills && !global._babelPolyfill) { | ||
// Temporarily remap [Array].toLocaleString to [Array].toString. | ||
// Fixes an issue with loading the polyfills within the v8 snapshot environment | ||
// where toLocaleString() within the TypedArray polyfills causes snapshot failure. | ||
var origToLocaleString = Array.prototype.toLocaleString, | ||
origTypedToLocaleString; | ||
Array.prototype.toLocaleString = Array.prototype.toString; | ||
if (global.Int8Array && Int8Array.prototype.toLocaleString) { | ||
origTypedToLocaleString = Int8Array.prototype.toLocaleString; | ||
Int8Array.prototype.toLocaleString = Int8Array.prototype.toString; | ||
} | ||
|
||
// Apply core-js polyfills | ||
require('./corejs-proxy'); | ||
|
||
// Restore real [Array].toLocaleString for runtime usage. | ||
if (origToLocaleString) Array.prototype.toLocaleString = origToLocaleString; | ||
if (origTypedToLocaleString) Int8Array.prototype.toLocaleString = origTypedToLocaleString; | ||
} |
Oops, something went wrong.