@corva/create-app 0.34.0-7 → 0.35.0-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,6 @@
1
1
  const { Option, InvalidArgumentError } = require('commander');
2
2
  const chalk = require('chalk');
3
+ const semver = require('semver');
3
4
 
4
5
  const flags = '--bump-version <string>';
5
6
  const description = 'Bump version';
@@ -18,6 +18,12 @@ const uiDependencies = {
18
18
  };
19
19
 
20
20
  const jsUiDevDependencies = {
21
+ '@testing-library/jest-dom': '^5.16.4',
22
+ '@testing-library/react': '12.1.5',
23
+ '@testing-library/react-hooks': '^8.0.1',
24
+ '@testing-library/user-event': '^14.3.0',
25
+ 'react-scripts': '4.0.3',
26
+ 'eslint': '7.32.0',
21
27
  'postcss-loader': '4.1.0',
22
28
  };
23
29
 
@@ -26,6 +32,7 @@ const tsUiDevDependencies = {
26
32
  '@tsconfig/create-react-app': '1.0.2',
27
33
  '@types/material-ui': '0.21.9',
28
34
  '@types/react': '^17.0.22',
35
+ '@types/jest': '26.0.24',
29
36
  '@types/react-dom': '^17.0.9',
30
37
  '@typescript-eslint/eslint-plugin': '^4.31.2',
31
38
  '@typescript-eslint/parser': '^4.31.2',
@@ -39,6 +46,7 @@ const uiScripts = {
39
46
  zip: 'create-corva-app zip .',
40
47
  lint: 'eslint --cache ./src/',
41
48
  release: 'create-corva-app release .',
49
+ test: 'react-scripts test',
42
50
  };
43
51
 
44
52
  const uiPackage = {
@@ -47,6 +55,11 @@ const uiPackage = {
47
55
  scripts: uiScripts,
48
56
  dependencies: uiDependencies,
49
57
  devDependencies: jsUiDevDependencies,
58
+ // TODO: This is a temporary workaround. Should be removed once
59
+ // this ticket is resolved: https://corvaqa.atlassian.net/browse/DC-3982
60
+ jest: {
61
+ transformIgnorePatterns: ['/node_modules/(?!@babel/runtime|@corva/ui)', '\\.pnp\\.[^\\/]+$'],
62
+ },
50
63
  };
51
64
 
52
65
  const tsUiPackage = {
@@ -19,6 +19,11 @@ class Manifest {
19
19
  return this.manifest.application.name
20
20
  }
21
21
 
22
+ get unix_name() {
23
+ // todo: npm scopes?
24
+ return this.manifest.application.key.replace(/\W+/gi, '_').toLowerCase();
25
+ }
26
+
22
27
  get description() {
23
28
  return this.manifest.application.description
24
29
  }
@@ -64,9 +64,16 @@ const transformPatternsIntoFileNames = async (dirName, patterns, ignoredFiles =
64
64
  return filesFromPatterns;
65
65
  };
66
66
 
67
- const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName }) => {
67
+ /**
68
+ *
69
+ * @param {string[]} itemsToZip
70
+ * @param {object} param1
71
+ * @param {import('../lib/manifest').Manifest} param1.manifest
72
+ * @returns
73
+ */
74
+ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName, manifest }) => {
68
75
  const version = await getIncreasedVersion(pkg.version, options);
69
- const zipFileName = `${pkg.name}-${version}.zip`;
76
+ const zipFileName = `${manifest.unix_name}-${version}.zip`;
70
77
  const itemsToSave = [];
71
78
  const shouldUpdateVersion = version !== pkg.version;
72
79
 
@@ -114,9 +121,16 @@ const resolveDataToZipUiApp = async (itemsToZip = [], { options, pkg, dirName })
114
121
  };
115
122
  };
116
123
 
117
- const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirName }) => {
124
+ /**
125
+ *
126
+ * @param {string[]} itemsToZip
127
+ * @param {object} param1
128
+ * @param {import('../lib/manifest').Manifest} param1.manifest
129
+ * @returns
130
+ */
131
+ const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirName, manifest }) => {
118
132
  const version = await getIncreasedVersion(pkg.version, options);
119
- const zipFileName = `${pkg.name}-${version}.zip`;
133
+ const zipFileName = `${manifest.unix_name}-${version}.zip`;
120
134
  const itemsToSave = [];
121
135
  const shouldUpdateVersion = version !== pkg.version;
122
136
 
@@ -135,7 +149,7 @@ const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirNa
135
149
  const packageDirContent = await fs.readdir(dirName);
136
150
  const shouldPushDefaultSrc = !itemsToZip.length;
137
151
 
138
- itemsToZip.push('config', 'manifest.json', 'package.json');
152
+ itemsToZip.push('config', 'manifest.json', 'package.json', '.nvmrc', '.npmrc');
139
153
 
140
154
  if (packageDirContent.includes('package-lock.json')) {
141
155
  itemsToZip.push('package-lock.json');
@@ -176,8 +190,15 @@ const resolveDataForZipNodeJsApp = async (itemsToZip = [], { options, pkg, dirNa
176
190
  };
177
191
  };
178
192
 
193
+ /**
194
+ *
195
+ * @param {string[]} itemsToZip
196
+ * @param {object} param1
197
+ * @param {import('../lib/manifest').Manifest} param1.manifest
198
+ * @returns
199
+ */
179
200
  const resolveDataForZipPythonApp = async (itemsToZip = [], { manifest, dirName, options }) => {
180
- const zipFileName = `${manifest.manifest.application.name}.zip`;
201
+ const zipFileName = `${manifest.unix_name}.zip`;
181
202
 
182
203
  if (!itemsToZip.length) {
183
204
  itemsToZip.push(...(await glob('**/*.py', { cwd: dirName, ignore: [...(options.ignoredFiles || []), 'venv/**/*'] })));
@@ -5,7 +5,7 @@ const resolveAppRuntime = (opts) => {
5
5
  return {
6
6
  language: opts.useTypescript ? "typescript" : "javascript",
7
7
  packageManager: opts.packageManager,
8
- version: process.version.replace(/^v/, ""),
8
+ version: 16,
9
9
  }
10
10
  }
11
11
 
package/lib/index.js CHANGED
@@ -351,11 +351,11 @@ async function addTemplate(root, manifest, runtime) {
351
351
  */
352
352
  async function configureApp(root, manifest, runtime) {
353
353
  if (manifest.isJs()) {
354
+ await addNvmRc(root, manifest, runtime);
354
355
  await addPackageJSON(root, manifest, runtime);
355
356
  }
356
357
 
357
358
  if (manifest.isNode()) {
358
- await addNvmRc(root, manifest, runtime);
359
359
  await addTsConfigs(root, manifest, runtime);
360
360
  }
361
361
 
@@ -431,7 +431,7 @@ function addPackageJSON(root, manifest, runtime) {
431
431
  const defaults = getDefaultsForPackageJson(manifest, runtime);
432
432
 
433
433
  const packageJson = {
434
- name: manifest.name.replace(/\W/g, ''),
434
+ name: manifest.unix_name,
435
435
  version: defaults.version,
436
436
  description: manifest.description || defaults.description,
437
437
  engines: {
@@ -441,6 +441,7 @@ function addPackageJSON(root, manifest, runtime) {
441
441
  scripts: defaults.scripts,
442
442
  dependencies: defaults.dependencies,
443
443
  devDependencies: defaults.devDependencies,
444
+ ...(defaults.jest && {jest: defaults.jest})
444
445
  };
445
446
 
446
447
  return fs.writeJSON(path.join(root, 'package.json'), packageJson, writejsonOptions);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.34.0-7",
3
+ "version": "0.35.0-2",
4
4
  "private": false,
5
5
  "description": "Create app to use it in CORVA.AI",
6
6
  "keywords": [
@@ -0,0 +1,31 @@
1
+ import { useState } from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import { Button } from '@corva/ui/components';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ const Toggle = () => {
7
+ const [isOn, setIsOn] = useState(false);
8
+
9
+ return (
10
+ <>
11
+ {isOn ? 'ON' : 'OFF'}
12
+ <Button onClick={() => setIsOn(value => !value)}>toggle</Button>
13
+ </>
14
+ );
15
+ };
16
+
17
+ describe('<Toggle />', () => {
18
+ it('should be OFF by default', () => {
19
+ render(<Toggle />);
20
+
21
+ expect(screen.getByText('OFF')).toBeInTheDocument();
22
+ });
23
+
24
+ it('should switch to ON after a single press', async () => {
25
+ render(<Toggle />);
26
+
27
+ userEvent.click(screen.getByText('toggle'));
28
+
29
+ await waitFor(() => screen.getByText('ON'));
30
+ });
31
+ });
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line
2
+ import '@testing-library/jest-dom/extend-expect';
@@ -2,6 +2,18 @@ import { Checkbox, FormControlLabel } from '@material-ui/core';
2
2
 
3
3
  import { DEFAULT_SETTINGS } from './constants';
4
4
 
5
+ /* Types */
6
+ interface AppSettingsProps {
7
+ app: { [key: string]: any };
8
+ appData: { [key: string]: any };
9
+ company: { [key: string]: any };
10
+ onSettingChange: (key: string, value: any) => void;
11
+ settings: {
12
+ isExampleCheckboxChecked: boolean;
13
+ };
14
+ user: { [key: string]: any };
15
+ }
16
+
5
17
  const AppSettings = (props: AppSettingsProps): JSX.Element => {
6
18
  const { settings: apiSettings, onSettingChange } = props;
7
19
  const settings = { ...DEFAULT_SETTINGS, ...apiSettings };
@@ -25,18 +37,6 @@ AppSettings.defaultProps = {
25
37
  company: {},
26
38
  };
27
39
 
28
- /* Types */
29
- interface AppSettingsProps {
30
- app: { [key: string]: any };
31
- appData: { [key: string]: any };
32
- company: { [key: string]: any };
33
- onSettingChange: (key: string, value: any) => void;
34
- settings: {
35
- isExampleCheckboxChecked: boolean;
36
- };
37
- user: { [key: string]: any };
38
- }
39
-
40
40
  // Important: Do not change root component default export (AppSettings.js). Use it as container
41
41
  // for your App Settings. It's required to make build and zip scripts work as expected;
42
42
  export default AppSettings;
@@ -0,0 +1,31 @@
1
+ import { useState } from 'react';
2
+ import { render, screen, waitFor } from '@testing-library/react';
3
+ import { Button } from '@corva/ui/components';
4
+ import userEvent from '@testing-library/user-event';
5
+
6
+ const Toggle = () => {
7
+ const [isOn, setIsOn] = useState<boolean>(false);
8
+
9
+ return (
10
+ <>
11
+ {isOn ? 'ON' : 'OFF'}
12
+ <Button onClick={() => setIsOn(value => !value)}>toggle</Button>
13
+ </>
14
+ );
15
+ };
16
+
17
+ describe('<Toggle />', () => {
18
+ it('should be OFF by default', () => {
19
+ render(<Toggle />);
20
+
21
+ expect(screen.getByText('OFF')).toBeInTheDocument();
22
+ });
23
+
24
+ it('should switch to ON after a single press', async () => {
25
+ render(<Toggle />);
26
+
27
+ userEvent.click(screen.getByText('toggle'));
28
+
29
+ await waitFor(() => screen.getByText('ON'));
30
+ });
31
+ });
@@ -1,4 +1,4 @@
1
- declare module "*.svg" {
1
+ declare module '*.svg' {
2
2
  const content: string;
3
3
  export default content;
4
4
  }
@@ -0,0 +1,2 @@
1
+ // eslint-disable-next-line
2
+ import '@testing-library/jest-dom/extend-expect';
@@ -1 +0,0 @@
1
- 16.*
@@ -1 +0,0 @@
1
- 16.*