-
Notifications
You must be signed in to change notification settings - Fork 79
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
1 parent
e7279fb
commit a2e3029
Showing
28 changed files
with
653 additions
and
14 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 |
---|---|---|
|
@@ -19,3 +19,4 @@ coverage.data | |
coverage/ | ||
.docusaurus | ||
.idea | ||
packages/botonic-cli/tests/dummy-project/package-lock.json |
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
This file was deleted.
Oops, something went wrong.
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 @@ | ||
import { join } from 'path' | ||
import { chdir, cwd } from 'process' | ||
|
||
import { BotonicAPIService } from '../src/botonic-api-service' | ||
|
||
const workingDirectory = cwd() | ||
const pathToBotonicProject = join(workingDirectory, 'tests', 'dummy-project') | ||
const botonicApiService = new BotonicAPIService() | ||
|
||
describe('TEST: BotonicApiService', () => { | ||
it('Builds correctly a project', async () => { | ||
chdir(pathToBotonicProject) | ||
const buildOut = await botonicApiService.build() | ||
expect(buildOut).toBe(true) | ||
chdir(workingDirectory) | ||
}) | ||
}) |
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 @@ | ||
describe('TEST: Deploy command', () => { | ||
it('', () => { | ||
expect(true).toBe(true) | ||
}) | ||
}) |
112 changes: 112 additions & 0 deletions
112
packages/botonic-cli/tests/dummy-project/.botonic-telemetry/analytics.js
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,112 @@ | ||
const Analytics = require('analytics-node') | ||
const fs = require('fs') | ||
const os = require('os') | ||
const path = require('path') | ||
const { execSync } = require('child_process') | ||
|
||
function readJSON(path) { | ||
return JSON.parse(fs.readFileSync(path, 'utf8')) | ||
} | ||
|
||
function writeJSON(path, object) { | ||
fs.writeFileSync(path, JSON.stringify(object)) | ||
} | ||
|
||
function isWindows() { | ||
return os.platform() === 'win32' | ||
} | ||
|
||
function execCommand(command) { | ||
try { | ||
return String(execSync(command)).trim() | ||
} catch (e) { | ||
return String(e) | ||
} | ||
} | ||
|
||
function getBotonicDependencies() { | ||
try { | ||
const packageJSON = readJSON('package.json') | ||
const botonicDependencies = Object.entries( | ||
packageJSON.dependencies | ||
).filter(([k, _]) => k.includes('@botonic')) | ||
return botonicDependencies | ||
} catch (e) { | ||
return String(e) | ||
} | ||
} | ||
|
||
const botonicHomePath = path.join(os.homedir(), '.botonic') | ||
const botonicCredentialsPath = path.join(botonicHomePath, 'credentials.json') | ||
const ANALYTICS_KEY = 'YD0jpJHNGW12uhLNbgB4wbdTRQ4Cy1Zu' | ||
|
||
let credentials | ||
const analytics = new Analytics(ANALYTICS_KEY, { flushAt: 1 }) | ||
|
||
function isAnalyticsEnabled() { | ||
return process.env.BOTONIC_DISABLE_ANALYTICS !== '1' | ||
} | ||
|
||
function getSystemInformation() { | ||
return { | ||
platform: os.platform(), | ||
arch: os.arch(), | ||
timezone: Intl.DateTimeFormat().resolvedOptions().timeZone, | ||
timestamp: new Date().toISOString(), | ||
is_tty: process.stdout.isTTY, | ||
framework_path: __dirname, | ||
system_path: isWindows() | ||
? execCommand('echo %PATH%') | ||
: execCommand('echo $PATH'), | ||
node_version: execCommand('node --version'), | ||
botonic_cli_version: execCommand('botonic --version'), | ||
botonic_dependencies: getBotonicDependencies(), | ||
} | ||
} | ||
|
||
function initializeCredentials() { | ||
if (!fs.existsSync(botonicHomePath)) fs.mkdirSync(botonicHomePath) | ||
const anonymous_id = Math.round(Math.random() * 100000000) | ||
writeJSON(botonicCredentialsPath, { analytics: { anonymous_id } }) | ||
} | ||
|
||
function readCredentials() { | ||
if (!fs.existsSync(botonicCredentialsPath)) { | ||
initializeCredentials() | ||
} | ||
try { | ||
credentials = readJSON(botonicCredentialsPath) | ||
} catch (e) { | ||
if (fs.existsSync(botonicCredentialsPath)) { | ||
console.warn('Credentials could not be loaded', e) | ||
} | ||
} | ||
} | ||
|
||
function track(event, properties = {}) { | ||
if ( | ||
isAnalyticsEnabled() && | ||
analytics && | ||
credentials && | ||
credentials.analytics | ||
) { | ||
properties = { | ||
...getSystemInformation(), | ||
...properties, | ||
} | ||
analytics.track({ | ||
event: event, | ||
anonymousId: credentials.analytics.anonymous_id, | ||
properties: properties, | ||
}) | ||
} | ||
} | ||
|
||
const MODE = process.argv[2] | ||
try { | ||
readCredentials() | ||
if (MODE === 'serve') track('Served Botonic CLI') | ||
if (MODE === 'train') track('Trained with Botonic train') | ||
} catch (e) { | ||
console.warn('Error tracking event', e) | ||
} |
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 @@ | ||
/* | ||
* This babel configuration is used along with Jest for execute tests, | ||
* do not modify to avoid conflicts with webpack.config.js. | ||
*/ | ||
|
||
module.exports = { | ||
presets: [ | ||
[ | ||
'@babel/preset-env', | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
[ | ||
'@babel/react', | ||
{ | ||
targets: { | ||
node: 'current', | ||
}, | ||
}, | ||
], | ||
], | ||
plugins: [ | ||
require('@babel/plugin-proposal-object-rest-spread'), | ||
require('@babel/plugin-proposal-class-properties'), | ||
require('@babel/plugin-transform-runtime'), | ||
], | ||
} |
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,60 @@ | ||
{ | ||
"name": "blank", | ||
"version": "1.0.0", | ||
"scripts": { | ||
"build": "webpack --env target=all --mode=production", | ||
"prestart": "node ./.botonic-telemetry/analytics.js serve", | ||
"start": "webpack serve --env target=dev --mode=development", | ||
"test": "jest", | ||
"pretrain": "node ./.botonic-telemetry/analytics.js train", | ||
"train": "node_modules/.bin/ts-node src/nlu/train-model.ts" | ||
}, | ||
"jest": { | ||
"rootDir": "tests", | ||
"transformIgnorePatterns": [ | ||
"/node_modules/(?!@botonic).+\\.(js|jsx|ts|tsx|mjs)$" | ||
], | ||
"moduleNameMapper": { | ||
"\\.(jpg|jpeg|png|gif|eot|otf|webp|svg|ttf|woff|woff2|mp4|webm|wav|mp3|m4a|aac|oga)$": "<rootDir>/__mocks__/fileMock.js", | ||
"\\.(scss|css|less)$": "<rootDir>/__mocks__/styleMock.js" | ||
} | ||
}, | ||
"dependencies": { | ||
"@babel/runtime": "^7.12.5", | ||
"@botonic/react": "~0.18.0" | ||
}, | ||
"devDependencies": { | ||
"@babel/core": "^7.12.10", | ||
"@babel/plugin-proposal-class-properties": "^7.12.1", | ||
"@babel/plugin-transform-runtime": "^7.12.10", | ||
"@babel/preset-env": "^7.12.11", | ||
"@babel/preset-react": "^7.12.10", | ||
"@hot-loader/react-dom": "^17.0.1", | ||
"analytics-node": "^3.4.0-beta.3", | ||
"babel-jest": "^26.6.3", | ||
"babel-loader": "^8.2.2", | ||
"chokidar": "^3.4.3", | ||
"clean-webpack-plugin": "^3.0.0", | ||
"copy-webpack-plugin": "^7.0.0", | ||
"css-loader": "^5.0.1", | ||
"file-loader": "^6.2.0", | ||
"html-webpack-plugin": "^5.0.0-alpha.17", | ||
"imagemin-gifsicle": "^6.0.0", | ||
"imagemin-jpegtran": "^6.0.0", | ||
"imagemin-optipng": "^7.0.0", | ||
"imagemin-svgo": "^7.0.0", | ||
"imagemin-webpack": "^5.0.0", | ||
"jest": "^26.6.3", | ||
"node-sass": "^5.0.0", | ||
"null-loader": "^4.0.1", | ||
"react-hot-loader": "^4.13.0", | ||
"sass": "^1.30.0", | ||
"sass-loader": "^10.1.0", | ||
"style-loader": "^2.0.0", | ||
"terser": "^5.5.1", | ||
"terser-webpack-plugin": "^5.0.3", | ||
"webpack": "^5.10.3", | ||
"webpack-cli": "^4.2.0", | ||
"webpack-dev-server": "^4.0.0-beta.0" | ||
} | ||
} |
Empty file.
Empty file.
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 @@ | ||
export const config = { defaultDelay: 0, defaultTyping: 0 } |
Empty file.
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 @@ | ||
export const locales = {} |
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 @@ | ||
export const plugins = [] |
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 @@ | ||
export const routes = [] |
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 @@ | ||
export const webchat = {} |
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 @@ | ||
export const webviews = [] |
1 change: 1 addition & 0 deletions
1
packages/botonic-cli/tests/dummy-project/tests/__mocks__/fileMock.js
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 = 'test-file-stub' |
1 change: 1 addition & 0 deletions
1
packages/botonic-cli/tests/dummy-project/tests/__mocks__/styleMock.js
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 = {} |
21 changes: 21 additions & 0 deletions
21
packages/botonic-cli/tests/dummy-project/tests/app.test.js
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,21 @@ | ||
import { | ||
BotonicInputTester, | ||
BotonicOutputTester, | ||
NodeApp, | ||
} from '@botonic/react' | ||
|
||
import { config } from '../src/' | ||
import { locales } from '../src/locales' | ||
import { plugins } from '../src/plugins' | ||
import { routes } from '../src/routes' | ||
|
||
const app = new NodeApp({ routes, locales, plugins, ...config }) | ||
|
||
const i = new BotonicInputTester(app) | ||
const o = new BotonicOutputTester(app) | ||
|
||
test('TEST: (404) NOT FOUND', async () => { | ||
await expect(i.text('whatever')).resolves.toBe( | ||
o.text("I don't understand you") | ||
) | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/botonic-cli/tests/dummy-project/webpack-entries/dev-entry.js
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,15 @@ | ||
import { DevApp } from '@botonic/react' | ||
|
||
import { config } from '../src' | ||
import { locales } from '../src/locales' | ||
import { plugins } from '../src/plugins' | ||
import { routes } from '../src/routes' | ||
import { webchat } from '../src/webchat' | ||
|
||
export const app = new DevApp({ | ||
routes, | ||
locales, | ||
plugins, | ||
...webchat, | ||
...config, | ||
}) |
8 changes: 8 additions & 0 deletions
8
packages/botonic-cli/tests/dummy-project/webpack-entries/node-entry.js
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,8 @@ | ||
import { NodeApp } from '@botonic/react' | ||
|
||
import { config } from '../src' | ||
import { locales } from '../src/locales' | ||
import { plugins } from '../src/plugins' | ||
import { routes } from '../src/routes' | ||
|
||
export const app = new NodeApp({ routes, locales, plugins, ...config }) |
5 changes: 5 additions & 0 deletions
5
packages/botonic-cli/tests/dummy-project/webpack-entries/webchat-entry.js
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 { WebchatApp } from '@botonic/react' | ||
|
||
import { webchat } from '../src/webchat' | ||
|
||
export const app = new WebchatApp(webchat) |
6 changes: 6 additions & 0 deletions
6
packages/botonic-cli/tests/dummy-project/webpack-entries/webviews-entry.js
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,6 @@ | ||
import { WebviewApp } from '@botonic/react' | ||
|
||
import { locales } from '../src/locales' | ||
import { webviews } from '../src/webviews' | ||
|
||
export const app = new WebviewApp({ webviews, locales }) |
Oops, something went wrong.