@corva/create-app 0.50.0-2 → 0.50.0-4

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.
Files changed (40) hide show
  1. package/README.md +1 -1
  2. package/lib/commands/attach.js +7 -0
  3. package/lib/commands/create.js +6 -1
  4. package/lib/commands/release.js +7 -0
  5. package/lib/commands/rerun.js +7 -1
  6. package/lib/commands/zip.js +8 -1
  7. package/lib/constants/messages.js +3 -3
  8. package/lib/constants/package.js +41 -9
  9. package/lib/flow.js +2 -2
  10. package/lib/main.js +9 -59
  11. package/package.json +2 -2
  12. package/templates/ui/javascript/config/jest/babelTransform.js +16 -0
  13. package/templates/ui/javascript/config/jest/cssTransform.js +16 -0
  14. package/templates/ui/javascript/config/jest/fileTransform.js +48 -0
  15. package/templates/ui/javascript/config/jest/globalSetup.js +5 -0
  16. package/templates/ui/javascript/config/jest/setupTests.js +11 -0
  17. package/templates/ui/javascript/gitignore +2 -0
  18. package/templates/ui/javascript/src/AppSettings.js +1 -0
  19. package/templates/ui/javascript/src/__mocks__/mockAppProps.js +580 -0
  20. package/templates/ui/javascript/src/__mocks__/mockAppSettingsProps.js +290 -0
  21. package/templates/ui/javascript/src/__tests__/App.test.js +21 -0
  22. package/templates/ui/javascript/src/__tests__/AppSettings.test.js +21 -0
  23. package/templates/ui/javascript/src/__tests__/TestsExample.test.js +37 -0
  24. package/templates/ui/typescript/config/jest/babelTransform.js +16 -0
  25. package/templates/ui/typescript/config/jest/cssTransform.js +16 -0
  26. package/templates/ui/typescript/config/jest/fileTransform.js +48 -0
  27. package/templates/ui/typescript/config/jest/globalSetup.js +5 -0
  28. package/templates/ui/typescript/config/jest/setupTests.js +11 -0
  29. package/templates/ui/typescript/gitignore +2 -0
  30. package/templates/ui/typescript/src/App.tsx +1 -1
  31. package/templates/ui/typescript/src/AppSettings.tsx +1 -0
  32. package/templates/ui/typescript/src/__mocks__/mockAppProps.ts +580 -0
  33. package/templates/ui/typescript/src/__mocks__/mockAppSettingsProps.ts +290 -0
  34. package/templates/ui/typescript/src/__tests__/App.test.tsx +21 -0
  35. package/templates/ui/typescript/src/__tests__/AppSettings.test.tsx +21 -0
  36. package/templates/ui/typescript/src/__tests__/TestsExample.test.tsx +37 -0
  37. package/templates/ui/javascript/src/__tests__/TestExample.test.js +0 -31
  38. package/templates/ui/javascript/src/setupTests.js +0 -2
  39. package/templates/ui/typescript/src/__tests__/TestExample.test.tsx +0 -31
  40. package/templates/ui/typescript/src/setupTests.ts +0 -2
package/README.md CHANGED
@@ -41,7 +41,7 @@ Usage: create-corva-app create <project-directory> [options]
41
41
  Create a new app
42
42
 
43
43
  Arguments:
44
- project-directory project directory to work with (default: "Current working dir")
44
+ project-directory Project directory to work with (default: "Current working dir")
45
45
 
46
46
  Options:
47
47
  --developerName [string] Enter the Developer Name (default: "O&G Company")
@@ -1,4 +1,6 @@
1
+ import chalk from 'chalk';
1
2
  import { Command } from 'commander';
3
+ import { ERROR_ICON } from '../constants/messages.js';
2
4
  import { runFlow } from '../flow.js';
3
5
  import { ATTACH_FLOW } from '../flows/attach.js';
4
6
  import { getRealWorkingDir } from '../helpers/commands.js';
@@ -18,4 +20,9 @@ export const attachCommand = new Command('attach')
18
20
  .addOption(originalCwdOption)
19
21
  .action(async (dirName, options) => {
20
22
  await runFlow(ATTACH_FLOW, { dirName: getRealWorkingDir(dirName, options), options });
23
+ })
24
+ .showHelpAfterError()
25
+ .showSuggestionAfterError(true)
26
+ .configureOutput({
27
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
21
28
  });
@@ -23,6 +23,7 @@ import { getRealWorkingDir } from '../helpers/commands.js';
23
23
  import { Manifest } from '../flows/lib/manifest.js';
24
24
  import { fillManifest } from '../helpers/manifest.js';
25
25
  import { getManifestMandatoryKeys, manifestOptions } from '../constants/manifest.js';
26
+ import { ERROR_ICON } from '../constants/messages.js';
26
27
 
27
28
  const __filename = fileURLToPath(import.meta.url);
28
29
  const __dirname = dirname(__filename);
@@ -36,7 +37,11 @@ export const createCommand = new Command('create')
36
37
  .description('Create a new app')
37
38
  .argument('[project-directory]', 'project directory to work with', process.argv[process.argv.length - 1])
38
39
  .addOption(originalCwdOption)
39
- .usage(`${chalk.green('<project-directory>')} [options]`);
40
+ .showHelpAfterError()
41
+ .showSuggestionAfterError(true)
42
+ .configureOutput({
43
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
44
+ });
40
45
 
41
46
  manifestOptions().forEach((value) => {
42
47
  const type = typeof value.default;
@@ -1,3 +1,4 @@
1
+ import chalk from 'chalk';
1
2
  import { Command, Option } from 'commander';
2
3
  import { runFlow } from '../flow.js';
3
4
  import { RELEASE_FLOW } from '../flows/release.js';
@@ -8,6 +9,7 @@ import { envOption } from '../options/env.js';
8
9
  import { originalCwdOption } from '../options/original-cwd.js';
9
10
  import { silentOption } from '../options/silent.js';
10
11
  import { ensureBumpVersion } from '../helpers/cli-version.js';
12
+ import { ERROR_ICON } from '../constants/messages.js';
11
13
 
12
14
  export const releaseCommand = new Command('release')
13
15
  .description('Release app')
@@ -40,4 +42,9 @@ export const releaseCommand = new Command('release')
40
42
  patterns,
41
43
  options,
42
44
  });
45
+ })
46
+ .showHelpAfterError()
47
+ .showSuggestionAfterError(true)
48
+ .configureOutput({
49
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
43
50
  });
@@ -1,5 +1,6 @@
1
+ import chalk from 'chalk';
1
2
  import { Command, Option } from 'commander';
2
-
3
+ import { ERROR_ICON } from '../constants/messages.js';
3
4
  import { runFlow } from '../flow.js';
4
5
  import { RERUN_FLOW } from '../flows/rerun.js';
5
6
  import { getRealWorkingDir } from '../helpers/commands.js';
@@ -22,4 +23,9 @@ export const rerunCommand = new Command('rerun')
22
23
  .addOption(originalCwdOption)
23
24
  .action(async (dirName, options) => {
24
25
  await runFlow(RERUN_FLOW, { dirName: getRealWorkingDir(dirName, options), options });
26
+ })
27
+ .showHelpAfterError()
28
+ .showSuggestionAfterError(true)
29
+ .configureOutput({
30
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
25
31
  });
@@ -1,3 +1,4 @@
1
+ import chalk from 'chalk';
1
2
  import { Command, Option } from 'commander';
2
3
  import _ from 'lodash/fp.js';
3
4
 
@@ -8,6 +9,7 @@ import { bumpVersionOption } from '../options/bump-version.js';
8
9
  import { originalCwdOption } from '../options/original-cwd.js';
9
10
  import { silentOption } from '../options/silent.js';
10
11
  import { ensureBumpVersion } from '../helpers/cli-version.js';
12
+ import { ERROR_ICON } from '../constants/messages.js';
11
13
 
12
14
  export const zipCommand = new Command('zip')
13
15
  .description('Bundle app')
@@ -29,4 +31,9 @@ export const zipCommand = new Command('zip')
29
31
  options,
30
32
  }).then(_.get('zipFileName'));
31
33
  }),
32
- );
34
+ )
35
+ .showHelpAfterError()
36
+ .showSuggestionAfterError(true)
37
+ .configureOutput({
38
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
39
+ });
@@ -1,12 +1,12 @@
1
1
  import chalk from 'chalk';
2
2
 
3
- export const SUCCESS_ICON = ' \n';
4
- export const ERROR_ICON = ' \n';
3
+ export const SUCCESS_ICON = '✅';
4
+ export const ERROR_ICON = '❌';
5
5
 
6
6
  export const RELEASE = {
7
7
  createZip: 'Creating zip archive...\n',
8
8
  createZipError: 'Could not create zip archive.',
9
- createZipSuccess: `Zip archive has been created ${SUCCESS_ICON}`,
9
+ createZipSuccess: `Zip archive has been created ${SUCCESS_ICON}\n`,
10
10
  getAuthToken: 'Reading auth token...',
11
11
  getAuthTokenError: `Could not find auth token or API_KEY in .env file.\nFor UI app please run ${chalk.cyan`yarn start`} and login to Corva to fetch it or set API_KEY in your .env file`,
12
12
  getAppKey: 'Reading app key...',
@@ -19,11 +19,14 @@ const uiDependencies = {
19
19
  const jsUiDevDependencies = {
20
20
  '@corva/dc-platform-shared': 'latest',
21
21
  '@corva/eslint-config-browser': 'latest',
22
- '@testing-library/jest-dom': '^5.16.4',
23
- '@testing-library/react': '12.1.5',
22
+ '@testing-library/jest-dom': '^5.14.1',
23
+ '@testing-library/react': '^12.1.5',
24
24
  '@testing-library/react-hooks': '^8.0.1',
25
- '@testing-library/user-event': '^14.3.0',
26
- 'react-scripts': '4.0.3',
25
+ '@testing-library/user-event': '^13.2.1',
26
+ 'jest-watch-typeahead': '^1.0.0',
27
+ 'jest': '^27.4.3',
28
+ 'babel-jest': '^27.4.2',
29
+ 'babel-preset-react-app': '^10.0.1',
27
30
  'eslint': '7.32.0',
28
31
  'postcss-loader': '4.1.0',
29
32
  };
@@ -33,8 +36,8 @@ const tsUiDevDependencies = {
33
36
  '@tsconfig/create-react-app': '1.0.2',
34
37
  '@types/material-ui': '0.21.9',
35
38
  '@types/react': '^17.0.22',
36
- '@types/jest': '26.0.24',
37
39
  '@types/react-dom': '^17.0.9',
40
+ '@types/jest': '^27.0.1',
38
41
  '@typescript-eslint/eslint-plugin': '^4.31.2',
39
42
  '@typescript-eslint/parser': '^4.31.2',
40
43
  'ts-loader': '8.2.0',
@@ -47,7 +50,8 @@ const uiScripts = {
47
50
  zip: 'create-corva-app zip .',
48
51
  lint: 'eslint --cache ./src/',
49
52
  release: 'create-corva-app release .',
50
- test: 'react-scripts test',
53
+ test: 'jest',
54
+ coverage: 'jest --coverage',
51
55
  };
52
56
 
53
57
  const uiPackage = {
@@ -56,10 +60,38 @@ const uiPackage = {
56
60
  scripts: uiScripts,
57
61
  dependencies: uiDependencies,
58
62
  devDependencies: jsUiDevDependencies,
59
- // TODO: This is a temporary workaround. Should be removed once
60
- // this ticket is resolved: https://corvaqa.atlassian.net/browse/DC-3982
61
63
  jest: {
62
- transformIgnorePatterns: ['/node_modules/(?!@babel/runtime|@corva/ui)', '\\.pnp\\.[^\\/]+$'],
64
+ roots: ['<rootDir>/src'],
65
+ collectCoverageFrom: ['src/**/*.{js,jsx,ts,tsx}', '!src/**/*.d.ts'],
66
+ coverageThreshold: {
67
+ global: {
68
+ branches: 60,
69
+ functions: 60,
70
+ lines: 60,
71
+ statements: 60,
72
+ },
73
+ },
74
+ setupFilesAfterEnv: ['<rootDir>/config/jest/setupTests.js'],
75
+ globalSetup: '<rootDir>/config/jest/globalSetup.js',
76
+ testMatch: ['<rootDir>/src/**/__tests__/**/*.{js,jsx,ts,tsx}', '<rootDir>/src/**/*.{spec,test}.{js,jsx,ts,tsx}'],
77
+ testEnvironment: 'jsdom',
78
+ transform: {
79
+ '^.+\\.(js|jsx|mjs|cjs|ts|tsx)$': '<rootDir>/config/jest/babelTransform.js',
80
+ '^.+\\.css$': '<rootDir>/config/jest/cssTransform.js',
81
+ '^(?!.*\\.(js|jsx|mjs|cjs|ts|tsx|css|json)$)': '<rootDir>/config/jest/fileTransform.js',
82
+ },
83
+ transformIgnorePatterns: [
84
+ '/node_modules/(?!.*@babel/runtime).+\\.(js|jsx|mjs|cjs|ts|tsx)$',
85
+ '^.+\\.module\\.(css|sass|scss)$',
86
+ ],
87
+ modulePaths: [],
88
+ moduleNameMapper: {
89
+ '~(.*)': '<rootDir>/src/$1',
90
+ '^.+\\.module\\.(css|sass|scss)$': 'identity-obj-proxy',
91
+ '@corva/ui(.*)': '@corva/ui/cjs-bundle/$1',
92
+ },
93
+ watchPlugins: ['jest-watch-typeahead/filename', 'jest-watch-typeahead/testname'],
94
+ resetMocks: true,
63
95
  },
64
96
  };
65
97
 
package/lib/flow.js CHANGED
@@ -16,7 +16,7 @@ export const runFlow = async (flow, context, indent = '') => {
16
16
 
17
17
  const result = await runSteps(flow.steps, context, indent + ' ');
18
18
 
19
- logger.write(`${indent}Done!` + SUCCESS_ICON);
19
+ logger.write(`${indent}Done!` + SUCCESS_ICON + '\n');
20
20
 
21
21
  return result;
22
22
  };
@@ -40,7 +40,7 @@ const runSteps = async (steps = [], context = {}, indent = '') => {
40
40
 
41
41
  Object.assign(context, result);
42
42
 
43
- logger.write(SUCCESS_ICON);
43
+ logger.write(SUCCESS_ICON + '\n');
44
44
  }
45
45
 
46
46
  return context;
package/lib/main.js CHANGED
@@ -1,10 +1,8 @@
1
1
  import chalk from 'chalk';
2
- import { Command, CommanderError } from 'commander';
2
+ import { Command } from 'commander';
3
3
  import semver from 'semver';
4
4
 
5
5
  import { warnIfOutdated } from './helpers/cli-version.js';
6
- import { ERROR_ICON } from './constants/messages.js';
7
- import { StepError } from './flows/lib/step-error.js';
8
6
  import { logger } from './helpers/logger.js';
9
7
 
10
8
  import { zipCommand } from './commands/zip.js';
@@ -13,6 +11,8 @@ import { rerunCommand } from './commands/rerun.js';
13
11
  import { attachCommand } from './commands/attach.js';
14
12
  import { createCommand } from './commands/create.js';
15
13
 
14
+ import { ERROR_ICON } from './constants/messages.js';
15
+
16
16
  function checkNodeVersion() {
17
17
  logger.write('Checking node version...');
18
18
 
@@ -40,70 +40,20 @@ export async function run() {
40
40
 
41
41
  await warnIfOutdated();
42
42
  })
43
- .configureOutput({ writeErr: () => undefined })
44
- .exitOverride()
45
43
  .addCommand(createCommand, { isDefault: true })
46
44
  .addCommand(zipCommand)
47
45
  .addCommand(releaseCommand)
48
46
  .addCommand(rerunCommand)
49
- .addCommand(attachCommand);
47
+ .addCommand(attachCommand)
48
+ .showHelpAfterError()
49
+ .showSuggestionAfterError(true)
50
+ .configureOutput({
51
+ outputError: (str, write) => write(chalk.red(`${ERROR_ICON} ${str}`)),
52
+ });
50
53
 
51
54
  try {
52
55
  await program.parseAsync(process.argv);
53
56
  } catch (e) {
54
- handleError(program, e);
55
-
56
57
  process.exit(1);
57
58
  }
58
59
  }
59
-
60
- const handleError = (program, e) => {
61
- if (e instanceof CommanderError) {
62
- handleCommanderError(program, e);
63
-
64
- return;
65
- }
66
-
67
- logger.write(ERROR_ICON);
68
-
69
- if (!(e instanceof StepError)) {
70
- console.error(chalk.red(e));
71
-
72
- return;
73
- }
74
-
75
- console.log(chalk.red(e.message));
76
- e.cause && console.error(chalk.red(e.cause));
77
- };
78
-
79
- const handleCommanderError = (program, e) => {
80
- switch (e.code) {
81
- case 'commander.missingArgument': {
82
- const match = /error:.*'(.*)'/.exec(e.message);
83
-
84
- if (match && match[1] === 'project-directory') {
85
- const commandName = program.args[0] || program._defaultCommandName;
86
-
87
- console.error('Please specify the project directory:');
88
- logger.log(` ${chalk.cyan(program.name())} ${commandName} ${chalk.green('<project-directory>')}`);
89
- logger.log();
90
- logger.log('For example:');
91
- logger.log(` ${chalk.cyan(program.name())} ${commandName} ${chalk.green('my-react-app')}`);
92
- logger.log();
93
- logger.log(`Run ${chalk.cyan(`${program.name()} help ${commandName}`)} to see all options.`);
94
- } else {
95
- console.error('❌', e.message);
96
- }
97
-
98
- break;
99
- }
100
- case 'commander.help':
101
- case 'commander.helpDisplayed': {
102
- // ignore
103
- break;
104
- }
105
- default: {
106
- console.error('❌', e.message);
107
- }
108
- }
109
- };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@corva/create-app",
3
- "version": "0.50.0-2",
3
+ "version": "0.50.0-4",
4
4
  "private": false,
5
5
  "description": "Create an app to use it in CORVA.AI",
6
6
  "keywords": [
@@ -35,7 +35,7 @@
35
35
  "release-rc": "npm run release -- --prerelease"
36
36
  },
37
37
  "lint-staged": {
38
- "*.{js,json}": "npm run lint:fix"
38
+ "*.js": "npm run lint:fix"
39
39
  },
40
40
  "dependencies": {
41
41
  "archiver": "^5.3.0",
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+
3
+ const babelJest = require('babel-jest').default;
4
+
5
+ module.exports = babelJest.createTransformer({
6
+ presets: [
7
+ [
8
+ require.resolve('babel-preset-react-app'),
9
+ {
10
+ runtime: 'automatic',
11
+ },
12
+ ],
13
+ ],
14
+ babelrc: false,
15
+ configFile: false,
16
+ });
@@ -0,0 +1,16 @@
1
+ /* eslint-disable */
2
+
3
+ // This is a custom Jest transformer turning style imports into empty objects.
4
+ // http://facebook.github.io/jest/docs/en/webpack.html
5
+
6
+ module.exports = {
7
+ process() {
8
+ return {
9
+ code: 'module.exports = {};',
10
+ };
11
+ },
12
+ getCacheKey() {
13
+ // The output is always the same.
14
+ return 'cssTransform';
15
+ },
16
+ };
@@ -0,0 +1,48 @@
1
+ /* eslint-disable */
2
+
3
+ const path = require('path');
4
+
5
+ // This is a custom Jest transformer turning file imports into filenames.
6
+ // http://facebook.github.io/jest/docs/en/webpack.html
7
+
8
+ const toPascalCase = str => {
9
+ const allWordsIterator = str.matchAll(/\w+/g);
10
+
11
+ return Array.from(allWordsIterator).reduce((acc, matchResult) => {
12
+ const word = matchResult[0];
13
+ return acc + word[0].toUpperCase() + word.slice(1).toLowerCase();
14
+ }, '');
15
+ };
16
+
17
+ module.exports = {
18
+ process(src, filename) {
19
+ const assetFilename = JSON.stringify(path.basename(filename));
20
+
21
+ if (filename.match(/\.svg$/)) {
22
+ // Based on how SVGR generates a component name:
23
+ // https://github.com/smooth-code/svgr/blob/01b194cf967347d43d4cbe6b434404731b87cf27/packages/core/src/state.js#L6
24
+ const pascalCaseFilename = toPascalCase(path.parse(filename).name);
25
+ const componentName = `Svg${pascalCaseFilename}`;
26
+ return {
27
+ code: `const React = require('react');
28
+ module.exports = {
29
+ __esModule: true,
30
+ default: ${assetFilename},
31
+ ReactComponent: React.forwardRef(function ${componentName}(props, ref) {
32
+ return {
33
+ $$typeof: Symbol.for('react.element'),
34
+ type: 'svg',
35
+ ref: ref,
36
+ key: null,
37
+ props: Object.assign({}, props, {
38
+ children: ${assetFilename}
39
+ })
40
+ };
41
+ }),
42
+ };`,
43
+ };
44
+ }
45
+
46
+ return { code: `module.exports = ${assetFilename};` };
47
+ },
48
+ };
@@ -0,0 +1,5 @@
1
+ module.exports = async () => {
2
+ // use UTC timezone to not break tests when you run them on
3
+ // an environemnt with a different timezone
4
+ process.env.TZ = 'UTC';
5
+ };
@@ -0,0 +1,11 @@
1
+ /* eslint-disable */
2
+
3
+ // jest-dom adds custom jest matchers for asserting on DOM nodes.
4
+ // allows you to do things like:
5
+ // expect(element).toHaveTextContent(/react/i)
6
+ // learn more: https://github.com/testing-library/jest-dom
7
+ // eslint-disable-next-line
8
+ import '@testing-library/jest-dom/extend-expect';
9
+
10
+ // Set UTC timezone for tests to not use the environment timezone
11
+ process.env.TZ = 'UTC';
@@ -10,6 +10,7 @@
10
10
 
11
11
  # production
12
12
  /build
13
+ /dist
13
14
 
14
15
  # misc
15
16
  .env
@@ -23,3 +24,4 @@
23
24
  npm-debug.log*
24
25
  yarn-debug.log*
25
26
  yarn-error.log*
27
+ .eslintcache
@@ -27,6 +27,7 @@ function AppSettings({
27
27
  label="Example checkbox"
28
28
  control={
29
29
  <Checkbox
30
+ data-testid="exampleCheckbox"
30
31
  checked={settings.isExampleCheckboxChecked}
31
32
  onChange={e => onSettingChange('isExampleCheckboxChecked', e.target.checked)}
32
33
  />