From 94717b8bfb87a73c65ff4287d05adca8c78bb9f6 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 27 Aug 2020 12:56:18 -0400 Subject: [PATCH 1/2] Add prettier setup to eslint config. --- .eslintrc.js | 15 ++++++++------- .prettierrc | 3 +++ package.json | 2 ++ yarn.lock | 31 +++++++++++++++++++++++++++++++ 4 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 .prettierrc diff --git a/.eslintrc.js b/.eslintrc.js index 7e4a6f4..a6b7ef9 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -3,23 +3,24 @@ module.exports = { plugins: ['node'], extends: [ 'eslint:recommended', - 'plugin:node/recommended' + 'plugin:node/recommended', + 'plugin:prettier/recommended', ], parserOptions: { sourceType: 'script', - ecmaVersion: 2017 + ecmaVersion: 2017, }, env: { browser: false, - node: true + node: true, }, overrides: [ // test files { files: ['tests/**/*.js'], env: { - qunit: true - } - } - ] + qunit: true, + }, + }, + ], }; diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..544138b --- /dev/null +++ b/.prettierrc @@ -0,0 +1,3 @@ +{ + "singleQuote": true +} diff --git a/package.json b/package.json index e078309..566379b 100644 --- a/package.json +++ b/package.json @@ -37,7 +37,9 @@ "ember-cli": "~3.20.0", "ember-cli-dependency-checker": "^3.2.0", "eslint": "^7.7.0", + "eslint-config-prettier": "^6.11.0", "eslint-plugin-node": "^11.1.0", + "eslint-plugin-prettier": "^3.1.4", "execa": "^4.0.3", "prettier": "^2.1.1", "qunit": "^2.11.1", diff --git a/yarn.lock b/yarn.lock index fb79559..855b463 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2587,6 +2587,13 @@ escape-string-regexp@^1.0.2, escape-string-regexp@^1.0.5: version "1.0.5" resolved "https://registry.yarnpkg.com/escape-string-regexp/-/escape-string-regexp-1.0.5.tgz#1b61c0562190a8dff6ae3bb2cf0200ca130b86d4" +eslint-config-prettier@^6.11.0: + version "6.11.0" + resolved "https://registry.yarnpkg.com/eslint-config-prettier/-/eslint-config-prettier-6.11.0.tgz#f6d2238c1290d01c859a8b5c1f7d352a0b0da8b1" + integrity sha512-oB8cpLWSAjOVFEJhhyMZh6NOEOtBVziaqdDQ86+qhDHFbZXoRTM7pNSvFRfW/W/L/LrQ38C99J5CGuRBBzBsdA== + dependencies: + get-stdin "^6.0.0" + eslint-plugin-es@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/eslint-plugin-es/-/eslint-plugin-es-3.0.0.tgz#98cb1bc8ab0aa807977855e11ad9d1c9422d014b" @@ -2607,6 +2614,13 @@ eslint-plugin-node@^11.1.0: resolve "^1.10.1" semver "^6.1.0" +eslint-plugin-prettier@^3.1.4: + version "3.1.4" + resolved "https://registry.yarnpkg.com/eslint-plugin-prettier/-/eslint-plugin-prettier-3.1.4.tgz#168ab43154e2ea57db992a2cd097c828171f75c2" + integrity sha512-jZDa8z76klRqo+TdGDTFJSavwbnWK2ZpqGKNZ+VvweMW516pDUMmQ2koXvxEE4JhzNvTv+radye/bWGBmA6jmg== + dependencies: + prettier-linter-helpers "^1.0.0" + eslint-scope@^5.1.0: version "5.1.0" resolved "https://registry.yarnpkg.com/eslint-scope/-/eslint-scope-5.1.0.tgz#d0f971dfe59c69e0cada684b23d49dbf82600ce5" @@ -2902,6 +2916,11 @@ fast-deep-equal@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/fast-deep-equal/-/fast-deep-equal-2.0.1.tgz#7b05218ddf9667bf7f370bf7fdb2cb15fdd0aa49" +fast-diff@^1.1.2: + version "1.2.0" + resolved "https://registry.yarnpkg.com/fast-diff/-/fast-diff-1.2.0.tgz#73ee11982d86caaf7959828d519cfe927fac5f03" + integrity sha512-xJuoT5+L99XlZ8twedaRf6Ax2TgQVxvgZOYoPKqZufmJib0tL2tegPBOZb1pVNgIhlqDlA0eO0c3wBvQcmzx4w== + fast-glob@^3.0.3: version "3.0.4" resolved "https://registry.yarnpkg.com/fast-glob/-/fast-glob-3.0.4.tgz#d484a41005cb6faeb399b951fd1bd70ddaebb602" @@ -3365,6 +3384,11 @@ get-stdin@^4.0.1: version "4.0.1" resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-4.0.1.tgz#b968c6b0a04384324902e8bf1a5df32579a450fe" +get-stdin@^6.0.0: + version "6.0.0" + resolved "https://registry.yarnpkg.com/get-stdin/-/get-stdin-6.0.0.tgz#9e09bf712b360ab9225e812048f71fde9c89657b" + integrity sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g== + get-stream@3.0.0, get-stream@^3.0.0: version "3.0.0" resolved "https://registry.yarnpkg.com/get-stream/-/get-stream-3.0.0.tgz#8e943d1358dc37555054ecbe2edb05aa174ede14" @@ -5892,6 +5916,13 @@ prepend-http@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/prepend-http/-/prepend-http-2.0.0.tgz#e92434bfa5ea8c19f41cdfd401d741a3c819d897" +prettier-linter-helpers@^1.0.0: + version "1.0.0" + resolved "https://registry.yarnpkg.com/prettier-linter-helpers/-/prettier-linter-helpers-1.0.0.tgz#d23d41fe1375646de2d0104d3454a3008802cf7b" + integrity sha512-GbK2cP9nraSSUF9N2XwUwqfzlAFlMNYYl+ShE/V+H8a9uNl/oUqB1w2EL54Jh0OlyRSd8RfWYJ3coVS4TROP2w== + dependencies: + fast-diff "^1.1.2" + prettier@^2.1.1: version "2.1.1" resolved "https://registry.yarnpkg.com/prettier/-/prettier-2.1.1.tgz#d9485dd5e499daa6cb547023b87a6cf51bee37d6" From ab0903b2cb774397a8ab1e5ab2e7b8f75b6f0354 Mon Sep 17 00:00:00 2001 From: Robert Jackson Date: Thu, 27 Aug 2020 12:57:05 -0400 Subject: [PATCH 2/2] yarn lint:js --fix --- commands/index.js | 206 +++++---- config/environment.js | 4 +- ember-cli-build.js | 2 +- features.js | 13 +- features/application-template-wrapper.js | 31 +- features/default-async-observers.js | 5 +- features/jquery-integration.js | 2 +- features/template-only-glimmer-components.js | 89 +++- index.js | 23 +- testem.js | 16 +- tests/commands-test.js | 460 ++++++++++++------- tests/optional-features-test.js | 201 ++++---- tests/utils-test.js | 68 +-- utils.js | 10 +- 14 files changed, 717 insertions(+), 413 deletions(-) diff --git a/commands/index.js b/commands/index.js index ea81b4c..20ac85c 100644 --- a/commands/index.js +++ b/commands/index.js @@ -17,7 +17,9 @@ const USAGE_MESSAGE = strip` To list all available features, run ${chalk.bold('ember feature:list')}. To enable a feature, run ${chalk.bold('ember feature:enable some-feature')}. - To disable a feature, run ${chalk.bold('ember feature:disable some-feature')}. + To disable a feature, run ${chalk.bold( + 'ember feature:disable some-feature' + )}. `; const SHARED = { @@ -33,7 +35,7 @@ const SHARED = { try { return this.project.resolveSync(configPath); - } catch(err) { + } catch (err) { if (err.code !== 'MODULE_NOT_FOUND') { throw err; } @@ -50,14 +52,24 @@ const SHARED = { let feature = FEATURES[name]; if (feature === undefined) { - console.log(chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`)); + console.log( + chalk.red(`Error: ${chalk.bold(name)} is not a valid feature.\n`) + ); return LIST_FEATURES.run.apply(this); } let configPath = this._ensureConfigFile(); - let configJSON = JSON.parse(fs.readFileSync(configPath, { encoding: 'UTF-8' })); + let configJSON = JSON.parse( + fs.readFileSync(configPath, { encoding: 'UTF-8' }) + ); if (!this._isFeatureAvailable(feature)) { - console.log(chalk.red(`Error: ${chalk.bold(name)} is only available in Ember ${feature.since} or above.`)); + console.log( + chalk.red( + `Error: ${chalk.bold(name)} is only available in Ember ${ + feature.since + } or above.` + ) + ); return; } @@ -67,114 +79,134 @@ const SHARED = { let config = {}; - Object.keys(FEATURES).forEach(feature => { + Object.keys(FEATURES).forEach((feature) => { if (feature === name) { config[feature] = value; - } else if(configJSON[feature] !== undefined) { + } else if (configJSON[feature] !== undefined) { config[feature] = configJSON[feature]; } }); - fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', { encoding: 'UTF-8' }); + fs.writeFileSync(configPath, JSON.stringify(config, null, 2) + '\n', { + encoding: 'UTF-8', + }); let state = value ? 'Enabled' : 'Disabled'; - console.log(chalk.green(`${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline('config/optional-features.json')} to source control!`)); - } + console.log( + chalk.green( + `${state} ${chalk.bold(name)}. Be sure to commit ${chalk.underline( + 'config/optional-features.json' + )} to source control!` + ) + ); + }, }; -const USAGE = Object.assign({ - name: 'feature', - description: 'Prints the USAGE.', - works: 'insideProject', - run() { - console.log(USAGE_MESSAGE); - } -}, SHARED); +const USAGE = Object.assign( + { + name: 'feature', + description: 'Prints the USAGE.', + works: 'insideProject', + run() { + console.log(USAGE_MESSAGE); + }, + }, + SHARED +); /* This forces strip`` to start counting the indentaiton */ const INDENT_START = ''; -const LIST_FEATURES = Object.assign({ - name: 'feature:list', - description: 'List all available features.', - works: 'insideProject', - run() { - console.log(USAGE_MESSAGE); - console.log('Available features:'); +const LIST_FEATURES = Object.assign( + { + name: 'feature:list', + description: 'List all available features.', + works: 'insideProject', + run() { + console.log(USAGE_MESSAGE); + console.log('Available features:'); - let hasFeatures = false; + let hasFeatures = false; - Object.keys(FEATURES).forEach(key => { - let feature = FEATURES[key]; + Object.keys(FEATURES).forEach((key) => { + let feature = FEATURES[key]; - if (this._isFeatureAvailable(feature)) { - console.log(strip` + if (this._isFeatureAvailable(feature)) { + console.log(strip` ${INDENT_START} ${chalk.bold(key)} ${chalk.cyan(`(Default: ${feature.default})`)} ${feature.description} - ${chalk.gray(`More information: ${chalk.underline(feature.url)}`)}`); - - hasFeatures = true; - } - }); - - if (hasFeatures) { - console.log(); - } else { - console.log(chalk.gray(strip` + ${chalk.gray( + `More information: ${chalk.underline(feature.url)}` + )}`); + + hasFeatures = true; + } + }); + + if (hasFeatures) { + console.log(); + } else { + console.log( + chalk.gray(strip` ${INDENT_START} No optional features available for your current Ember version. - `)); - } - } -}, SHARED); - -const ENABLE_FEATURE = Object.assign({ - name: 'feature:enable', - description: 'Enable feature.', - works: 'insideProject', - availableOptions: [ - { - name: 'run-codemod', - type: Boolean, - description: 'run any associated codemods without prompting' - // intentionally not setting a default, when the value is undefined the - // command will prompt the user + `) + ); + } }, - ], - anonymousOptions: [ - '' - ], - run(commandOptions, args) { - return this._setFeature(args[0], true, commandOptions.runCodemod); - } -}, SHARED); - -const DISABLE_FEATURE = Object.assign({ - name: 'feature:disable', - description: 'Disable feature.', - works: 'insideProject', - availableOptions: [ - { - name: 'run-codemod', - type: Boolean, - description: 'run any associated codemods without prompting' - // intentionally not setting a default, when the value is undefined the - // command will prompt the user + }, + SHARED +); + +const ENABLE_FEATURE = Object.assign( + { + name: 'feature:enable', + description: 'Enable feature.', + works: 'insideProject', + availableOptions: [ + { + name: 'run-codemod', + type: Boolean, + description: 'run any associated codemods without prompting', + // intentionally not setting a default, when the value is undefined the + // command will prompt the user + }, + ], + anonymousOptions: [''], + run(commandOptions, args) { + return this._setFeature(args[0], true, commandOptions.runCodemod); }, - ], - anonymousOptions: [ - '' - ], - run(commandOptions, args) { - return this._setFeature(args[0], false, commandOptions.runCodemod); - } -}, SHARED); + }, + SHARED +); + +const DISABLE_FEATURE = Object.assign( + { + name: 'feature:disable', + description: 'Disable feature.', + works: 'insideProject', + availableOptions: [ + { + name: 'run-codemod', + type: Boolean, + description: 'run any associated codemods without prompting', + // intentionally not setting a default, when the value is undefined the + // command will prompt the user + }, + ], + anonymousOptions: [''], + run(commandOptions, args) { + return this._setFeature(args[0], false, commandOptions.runCodemod); + }, + }, + SHARED +); module.exports = { - 'feature': USAGE, + feature: USAGE, 'feature:list': LIST_FEATURES, 'feature:enable': ENABLE_FEATURE, - 'feature:disable': DISABLE_FEATURE -} + 'feature:disable': DISABLE_FEATURE, +}; diff --git a/config/environment.js b/config/environment.js index 0dfaed4..331ab30 100644 --- a/config/environment.js +++ b/config/environment.js @@ -1,5 +1,5 @@ 'use strict'; -module.exports = function(/* environment, appConfig */) { - return { }; +module.exports = function (/* environment, appConfig */) { + return {}; }; diff --git a/ember-cli-build.js b/ember-cli-build.js index dc5a39e..ba0649d 100644 --- a/ember-cli-build.js +++ b/ember-cli-build.js @@ -2,7 +2,7 @@ const EmberAddon = require('ember-cli/lib/broccoli/ember-addon'); -module.exports = function(defaults) { +module.exports = function (defaults) { let app = new EmberAddon(defaults, { // Add options here }); diff --git a/features.js b/features.js index ae170c4..e7e4d1b 100644 --- a/features.js +++ b/features.js @@ -6,11 +6,14 @@ const path = require('path'); const FEATURES_PATH = path.resolve(__dirname, './features'); const FEATURES = {}; -glob.sync('*.js', { cwd: FEATURES_PATH }).sort().forEach(filename => { - let key = filename.slice(0, -3); - let value = Object.assign({}, require(`./features/${key}`)); +glob + .sync('*.js', { cwd: FEATURES_PATH }) + .sort() + .forEach((filename) => { + let key = filename.slice(0, -3); + let value = Object.assign({}, require(`./features/${key}`)); - FEATURES[key] = Object.freeze(value); -}); + FEATURES[key] = Object.freeze(value); + }); module.exports = Object.freeze(FEATURES); diff --git a/features/application-template-wrapper.js b/features/application-template-wrapper.js index a22962c..9621e37 100644 --- a/features/application-template-wrapper.js +++ b/features/application-template-wrapper.js @@ -9,7 +9,8 @@ const path = require('path'); const strip = require('../utils').strip; module.exports = { - description: 'Wrap the top-level application template (application.hbs) with a `
` element.', + description: + 'Wrap the top-level application template (application.hbs) with a `
` element.', url: 'https://github.com/emberjs/rfcs/pull/280', default: true, since: '3.1.0', @@ -26,7 +27,13 @@ module.exports = { if (isPod) { // TODO - console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n`)); + console.log( + chalk.yellow( + `${chalk.bold( + 'Note:' + )} There is an automated refactor script available for this feature, but it does not currently support "pod" apps. PRs welcome!\n` + ) + ); return; } else { templatePath = 'app/templates/application.hbs'; @@ -35,8 +42,10 @@ module.exports = { let absolutePath = path.join(root, templatePath); try { - originalContent = await p(fs.readFile)(absolutePath, { encoding: 'UTF-8' }); - } catch(err) { + originalContent = await p(fs.readFile)(absolutePath, { + encoding: 'UTF-8', + }); + } catch (err) { if (err.code === 'ENOENT') { return; } else { @@ -58,7 +67,9 @@ module.exports = { - Depending on your choice of \`rootElement\`, your app might not be wrapped inside a block-level element anymore. - For more information, see ${chalk.underline('https://github.com/emberjs/rfcs/pull/280')}. + For more information, see ${chalk.underline( + 'https://github.com/emberjs/rfcs/pull/280' + )}. To be very conservative, I could add the \`
\` wrapper to your application.hbs. (You can always remove it later.) `); @@ -67,7 +78,7 @@ module.exports = { type: 'confirm', name: 'shouldRewrite', message: 'Would you like me to do that for you?', - default: false + default: false, }); console.log(); @@ -93,7 +104,7 @@ module.exports = { content.push('
'); - lines.forEach(line => { + lines.forEach((line) => { content.push(line === '' ? '' : ` ${line}`); }); @@ -105,9 +116,11 @@ module.exports = { console.log(` ${chalk.yellow('overwrite')} ${templatePath}`); - await p(fs.writeFile)(templatePath, content.join('\n'), { encoding: 'UTF-8' }); + await p(fs.writeFile)(templatePath, content.join('\n'), { + encoding: 'UTF-8', + }); console.log(); } - } + }, }; diff --git a/features/default-async-observers.js b/features/default-async-observers.js index bad7669..d664477 100644 --- a/features/default-async-observers.js +++ b/features/default-async-observers.js @@ -2,8 +2,9 @@ 'use strict'; module.exports = { - description: 'Makes all observers asynchronous (unless manually indicated as synchronous when calling addObserver/observes).', + description: + 'Makes all observers asynchronous (unless manually indicated as synchronous when calling addObserver/observes).', url: 'https://github.com/emberjs/rfcs/pull/494', default: false, - since: '3.13.0' + since: '3.13.0', }; diff --git a/features/jquery-integration.js b/features/jquery-integration.js index e8fc9e4..a3e49f8 100644 --- a/features/jquery-integration.js +++ b/features/jquery-integration.js @@ -5,5 +5,5 @@ module.exports = { description: 'Adds jQuery to the Ember application.', url: 'https://github.com/emberjs/rfcs/pull/294', default: true, - since: '3.0.0' + since: '3.0.0', }; diff --git a/features/template-only-glimmer-components.js b/features/template-only-glimmer-components.js index 7975537..ece1b62 100644 --- a/features/template-only-glimmer-components.js +++ b/features/template-only-glimmer-components.js @@ -21,7 +21,8 @@ const ComponentFile = strip` const INDENT_START = ''; module.exports = { - description: 'Use Glimmer Components semantics for template-only components (component templates with no corresponding .js file).', + description: + 'Use Glimmer Components semantics for template-only components (component templates with no corresponding .js file).', url: 'https://github.com/emberjs/rfcs/pull/278', default: false, since: '3.1.0', @@ -37,13 +38,25 @@ module.exports = { let podsFolder; if (podModulePrefix) { if (!modulePrefix || !podModulePrefix.startsWith(`${modulePrefix}/`)) { - console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`)); + console.log( + chalk.yellow( + `${chalk.bold( + 'Note:' + )} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n` + ) + ); return; } podsFolder = podModulePrefix.slice(modulePrefix.length + 1); if (!podsFolder) { - console.log(chalk.yellow(`${chalk.bold('Note:')} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n`)); + console.log( + chalk.yellow( + `${chalk.bold( + 'Note:' + )} There is an automated refactor script available for this feature, but your \`podModulePrefix\` could not be processed correctly.\n` + ) + ); return; } } @@ -55,13 +68,19 @@ module.exports = { let templatesRoot = path.join(root, 'app/templates/components'); let templateCandidates = await p(glob)('**/*.hbs', { cwd: templatesRoot }); - templateCandidates.forEach(template => { + templateCandidates.forEach((template) => { let templatePath = path.join('app/templates/components', template); - let jsPath = path.join('app/components', template.replace(/\.hbs$/, '.js')); + let jsPath = path.join( + 'app/components', + template.replace(/\.hbs$/, '.js') + ); if (fs.existsSync(path.join(root, jsPath))) return; - let tsPath = path.join('app/components', template.replace(/\.hbs$/, '.ts')); + let tsPath = path.join( + 'app/components', + template.replace(/\.hbs$/, '.ts') + ); if (fs.existsSync(path.join(root, tsPath))) return; templates.push(templatePath); @@ -71,15 +90,23 @@ module.exports = { // Handle "Pods" layout without prefix let componentsRoot = path.join(root, 'app/components'); - templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot }); + templateCandidates = await p(glob)('**/template.hbs', { + cwd: componentsRoot, + }); - templateCandidates.forEach(template => { + templateCandidates.forEach((template) => { let templatePath = path.join('app/components', template); - let jsPath = path.join('app/components', template.replace(/template\.hbs$/, 'component.js')); + let jsPath = path.join( + 'app/components', + template.replace(/template\.hbs$/, 'component.js') + ); if (fs.existsSync(path.join(root, jsPath))) return; - let tsPath = path.join('app/components', template.replace(/template\.hbs$/, 'component.ts')); + let tsPath = path.join( + 'app/components', + template.replace(/template\.hbs$/, 'component.ts') + ); if (fs.existsSync(path.join(root, tsPath))) return; templates.push(templatePath); @@ -89,15 +116,23 @@ module.exports = { // Handle "Pods" layout *with* prefix componentsRoot = path.join(root, `app/${podsFolder}/components`); - templateCandidates = await p(glob)('**/template.hbs', { cwd: componentsRoot }); + templateCandidates = await p(glob)('**/template.hbs', { + cwd: componentsRoot, + }); - templateCandidates.forEach(template => { + templateCandidates.forEach((template) => { let templatePath = path.join(`app/${podsFolder}/components`, template); - let jsPath = path.join(`app/${podsFolder}/components`, template.replace(/template\.hbs$/, 'component.js')); + let jsPath = path.join( + `app/${podsFolder}/components`, + template.replace(/template\.hbs$/, 'component.js') + ); if (fs.existsSync(path.join(root, jsPath))) return; - let tsPath = path.join(`app/${podsFolder}/components`, template.replace(/template\.hbs$/, 'component.ts')); + let tsPath = path.join( + `app/${podsFolder}/components`, + template.replace(/template\.hbs$/, 'component.ts') + ); if (fs.existsSync(path.join(root, tsPath))) return; templates.push(templatePath); @@ -122,19 +157,27 @@ module.exports = { - Passing classes in the invocation (i.e. \`{{my-component class="..."}}\`) will not work, since there is no wrapper element to apply the classes to. - For more information, see ${chalk.underline('https://github.com/emberjs/rfcs/pull/278')}. + For more information, see ${chalk.underline( + 'https://github.com/emberjs/rfcs/pull/278' + )}. - While these changes may be desirable for ${chalk.italic('new components')}, they may unexpectedly break the styling or runtime behavior of your ${chalk.italic('existing components')}. + While these changes may be desirable for ${chalk.italic( + 'new components' + )}, they may unexpectedly break the styling or runtime behavior of your ${chalk.italic( + 'existing components' + )}. To be conservative, it is recommended that you add a \`.js\` file for existing template-only components. (You can always delete them later if you aren't relying on the differences.) The following components are affected:`); - for (let i=0; i { + keys.forEach((key) => { if (FEATURES[key] === undefined) { - throw new SilentError(`Unknown feature "${key}" found in config/optional-features.json`); + throw new SilentError( + `Unknown feature "${key}" found in config/optional-features.json` + ); } else if (features[key] !== null && typeof features[key] !== 'boolean') { - throw new SilentError(`Unsupported value "${String(features[key])}" for "${key}" found in config/optional-features.json`); + throw new SilentError( + `Unsupported value "${String( + features[key] + )}" for "${key}" found in config/optional-features.json` + ); } }); - Object.keys(FEATURES).forEach(key => { + Object.keys(FEATURES).forEach((key) => { if (typeof features[key] === 'boolean') { validated[key] = features[key]; } @@ -59,7 +65,7 @@ module.exports = { isFeatureEnabled(name) { let value = this._features[name]; - return value !== undefined ? value : FEATURES[name].default; + return value !== undefined ? value : FEATURES[name].default; }, isFeatureExplicitlySet(name) { @@ -70,16 +76,15 @@ module.exports = { let EmberENV = {}; let features = this._features; - Object.keys(FEATURES).forEach(key => { + Object.keys(FEATURES).forEach((key) => { let value = features[key]; if (value !== undefined) { let KEY = `_${key.toUpperCase().replace(/-/g, '_')}`; EmberENV[KEY] = value; } - }); return { EmberENV }; - } + }, }; diff --git a/testem.js b/testem.js index b3799ce..6a52313 100644 --- a/testem.js +++ b/testem.js @@ -1,12 +1,8 @@ module.exports = { test_page: 'tests/index.html?hidepassed', disable_watching: true, - launch_in_ci: [ - 'Chrome' - ], - launch_in_dev: [ - 'Chrome' - ], + launch_in_ci: ['Chrome'], + launch_in_dev: ['Chrome'], browser_args: { Chrome: { mode: 'ci', @@ -14,8 +10,8 @@ module.exports = { '--disable-gpu', '--headless', '--remote-debugging-port=0', - '--window-size=1440,900' - ] - } - } + '--window-size=1440,900', + ], + }, + }, }; diff --git a/tests/commands-test.js b/tests/commands-test.js index d95e6f0..9e57e40 100644 --- a/tests/commands-test.js +++ b/tests/commands-test.js @@ -21,7 +21,7 @@ function run(...args) { return execa('ember', args, options); } -QUnit.module('commands', hooks => { +QUnit.module('commands', (hooks) => { let project; hooks.beforeEach(async function () { @@ -39,7 +39,7 @@ QUnit.module('commands', hooks => { "ember-source": "*" } } - ` + `, }); process.chdir(project.path()); @@ -49,13 +49,17 @@ QUnit.module('commands', hooks => { fs.symlinkSync(CWD, p(CWD, 'node_modules', '@ember', 'optional-features')); mkdirp.sync(p(CWD, 'node_modules', 'ember-source')); - fs.writeFileSync(p(CWD, 'node_modules', 'ember-source', 'package.json'), strip` + fs.writeFileSync( + p(CWD, 'node_modules', 'ember-source', 'package.json'), + strip` { "name": "ember-source", "description": "", "version": "9.9.9" } - `, { encoding: 'UTF-8' }); + `, + { encoding: 'UTF-8' } + ); }); hooks.afterEach(async function () { @@ -69,7 +73,10 @@ QUnit.module('commands', hooks => { QUnit.test(`it prints the USAGE message`, async function (assert) { let result = await run(command); - assert.ok(result.stdout.indexOf('Usage:') >= 0, 'it should print the USAGE message'); + assert.ok( + result.stdout.indexOf('Usage:') >= 0, + 'it should print the USAGE message' + ); }); } @@ -83,14 +90,26 @@ QUnit.module('commands', hooks => { QUnit.test(`it lists all the available features`, async function (assert) { let result = await run('feature:list'); - assert.ok(result.stdout.indexOf('Available features:') >= 0, 'it list the available features'); + assert.ok( + result.stdout.indexOf('Available features:') >= 0, + 'it list the available features' + ); - Object.keys(FEATURES).forEach(key => { + Object.keys(FEATURES).forEach((key) => { let feature = FEATURES[key]; - assert.ok(result.stdout.indexOf(`${key} (Default: ${feature.default}`) >= 0, `it should include ${key} and its default value`); - assert.ok(result.stdout.indexOf(feature.description) >= 0, `it should include the description for ${key}`); - assert.ok(result.stdout.indexOf(feature.url) >= 0, `it should include the URL for ${key}`); + assert.ok( + result.stdout.indexOf(`${key} (Default: ${feature.default}`) >= 0, + `it should include ${key} and its default value` + ); + assert.ok( + result.stdout.indexOf(feature.description) >= 0, + `it should include the description for ${key}` + ); + assert.ok( + result.stdout.indexOf(feature.url) >= 0, + `it should include the URL for ${key}` + ); }); }); }); @@ -98,12 +117,13 @@ QUnit.module('commands', hooks => { [ { command: 'feature:enable', - expected: true - }, { + expected: true, + }, + { command: 'feature:disable', - expected: false - } - ].forEach(testCase => { + expected: false, + }, + ].forEach((testCase) => { QUnit.module(testCase.command, () => { QUnit.test('it honors customized config path', async function (assert) { project.write({ @@ -121,42 +141,63 @@ QUnit.module('commands', hooks => { "configPath": "foo/bar" } } - ` + `, }); - await run(testCase.command, 'application-template-wrapper', { input: 'no\n' }); + await run(testCase.command, 'application-template-wrapper', { + input: 'no\n', + }); - assert.deepEqual(project.read('foo/bar'), { - 'optional-features.json': strip` + assert.deepEqual( + project.read('foo/bar'), + { + 'optional-features.json': strip` { "application-template-wrapper": ${testCase.expected} } - ` - }, 'it should have created the config file with the appropiate flags'); + `, + }, + 'it should have created the config file with the appropiate flags' + ); }); - QUnit.test('it creates the config file if one does not already exists', async function (assert) { - await run(testCase.command, 'application-template-wrapper', { input: 'no\n' }); + QUnit.test( + 'it creates the config file if one does not already exists', + async function (assert) { + await run(testCase.command, 'application-template-wrapper', { + input: 'no\n', + }); - assert.deepEqual(project.read('config'), { - 'optional-features.json': strip` + assert.deepEqual( + project.read('config'), + { + 'optional-features.json': strip` { "application-template-wrapper": ${testCase.expected} } - ` - }, 'it should have created the config file with the appropiate flags'); - }); + `, + }, + 'it should have created the config file with the appropiate flags' + ); + } + ); QUnit.test('it errors on invalid features', async function (assert) { let result = await run(testCase.command, 'foo-bar'); - assert.ok(result.stdout.indexOf('Error:') >= 0, 'it should print an error'); - assert.ok(result.stdout.indexOf('foo-bar is not a valid feature') >= 0, 'it should print an error'); + assert.ok( + result.stdout.indexOf('Error:') >= 0, + 'it should print an error' + ); + assert.ok( + result.stdout.indexOf('foo-bar is not a valid feature') >= 0, + 'it should print an error' + ); }); QUnit.test('it errors on invalid ember version', async function (assert) { project.write({ - 'node_modules': { + node_modules: { 'ember-source': { 'package.json': strip` { @@ -164,43 +205,65 @@ QUnit.module('commands', hooks => { "description": "", "version": "3.0.0" } - ` - } - } + `, + }, + }, }); - let result = await run(testCase.command, 'application-template-wrapper'); - - assert.ok(result.stdout.indexOf('Error:') >= 0, 'it should print an error'); - assert.ok(result.stdout.indexOf('application-template-wrapper is only available in Ember 3.1.0 or above') >= 0, 'it should print an error'); + let result = await run( + testCase.command, + 'application-template-wrapper' + ); + + assert.ok( + result.stdout.indexOf('Error:') >= 0, + 'it should print an error' + ); + assert.ok( + result.stdout.indexOf( + 'application-template-wrapper is only available in Ember 3.1.0 or above' + ) >= 0, + 'it should print an error' + ); }); - QUnit.test('it rewrites the config file if one already exists', async function (assert) { - project.write({ - config: { - 'optional-features.json': strip(` + QUnit.test( + 'it rewrites the config file if one already exists', + async function (assert) { + project.write({ + config: { + 'optional-features.json': strip(` { "template-only-glimmer-components": true } - `) - } - }); + `), + }, + }); - await run(testCase.command, 'application-template-wrapper', { input: 'no\n' }); + await run(testCase.command, 'application-template-wrapper', { + input: 'no\n', + }); - assert.deepEqual(project.read('config'), { - 'optional-features.json': strip` + assert.deepEqual( + project.read('config'), + { + 'optional-features.json': strip` { "application-template-wrapper": ${testCase.expected}, "template-only-glimmer-components": true } - ` - }, 'it should have rewritten the config file with the appropiate flags'); - }); + `, + }, + 'it should have rewritten the config file with the appropiate flags' + ); + } + ); - QUnit.test('it rewrites the config file with a custom config path', async function (assert) { - project.write({ - 'package.json': strip` + QUnit.test( + 'it rewrites the config file with a custom config path', + async function (assert) { + project.write({ + 'package.json': strip` { "name": "dummy", "description": "", @@ -214,37 +277,49 @@ QUnit.module('commands', hooks => { "configPath": "foo/bar" } } - ` - }); + `, + }); - project.write({ - 'optional-features.json': strip(` + project.write( + { + 'optional-features.json': strip(` { "template-only-glimmer-components": true } - `) - }, 'foo/bar'); + `), + }, + 'foo/bar' + ); - await run(testCase.command, 'application-template-wrapper', { input: 'no\n' }); + await run(testCase.command, 'application-template-wrapper', { + input: 'no\n', + }); - assert.deepEqual(project.read('foo/bar'), { - 'optional-features.json': strip` + assert.deepEqual( + project.read('foo/bar'), + { + 'optional-features.json': strip` { "application-template-wrapper": ${testCase.expected}, "template-only-glimmer-components": true } - ` - }, 'it should have rewritten the config file with the appropiate flags'); - }); + `, + }, + 'it should have rewritten the config file with the appropiate flags' + ); + } + ); }); }); QUnit.module('feature:disable application-template-wrapper', () => { - QUnit.test('it rewrites application.hbs without prompt when asked to', async function (assert) { - project.write({ - app: { - templates: { - 'application.hbs': strip` + QUnit.test( + 'it rewrites application.hbs without prompt when asked to', + async function (assert) { + project.write({ + app: { + templates: { + 'application.hbs': strip`
  • One
  • Two
  • @@ -254,15 +329,21 @@ QUnit.module('commands', hooks => { {{outlet}} - ` - } - } - }); + `, + }, + }, + }); - await run('feature:disable', 'application-template-wrapper', '--run-codemod'); + await run( + 'feature:disable', + 'application-template-wrapper', + '--run-codemod' + ); - assert.deepEqual(project.read('app/templates'), { - 'application.hbs': strip` + assert.deepEqual( + project.read('app/templates'), + { + 'application.hbs': strip`
    • One
    • @@ -274,11 +355,16 @@ QUnit.module('commands', hooks => {
    - ` - }, 'it should have rewritten the template with the wrapper'); - }); + `, + }, + 'it should have rewritten the template with the wrapper' + ); + } + ); - QUnit.test('it rewrites application.hbs when asked to', async function (assert) { + QUnit.test('it rewrites application.hbs when asked to', async function ( + assert + ) { project.write({ app: { templates: { @@ -292,15 +378,19 @@ QUnit.module('commands', hooks => { {{outlet}} - ` - } - } + `, + }, + }, }); - await run('feature:disable', 'application-template-wrapper', { input: 'yes\n' }); + await run('feature:disable', 'application-template-wrapper', { + input: 'yes\n', + }); - assert.deepEqual(project.read('app/templates'), { - 'application.hbs': strip` + assert.deepEqual( + project.read('app/templates'), + { + 'application.hbs': strip`
    • One
    • @@ -312,15 +402,19 @@ QUnit.module('commands', hooks => {
    - ` - }, 'it should have rewritten the template with the wrapper'); + `, + }, + 'it should have rewritten the template with the wrapper' + ); }); - QUnit.test('it does not rewrite application.hbs when asked not to', async function (assert) { - project.write({ - app: { - templates: { - 'application.hbs': strip` + QUnit.test( + 'it does not rewrite application.hbs when asked not to', + async function (assert) { + project.write({ + app: { + templates: { + 'application.hbs': strip`
    • One
    • Two
    • @@ -330,15 +424,19 @@ QUnit.module('commands', hooks => { {{outlet}} - ` - } - } - }); + `, + }, + }, + }); - await run('feature:disable', 'application-template-wrapper', { input: 'no\n' }); + await run('feature:disable', 'application-template-wrapper', { + input: 'no\n', + }); - assert.deepEqual(project.read('app/templates'), { - 'application.hbs': strip` + assert.deepEqual( + project.read('app/templates'), + { + 'application.hbs': strip`
      • One
      • Two
      • @@ -348,9 +446,12 @@ QUnit.module('commands', hooks => { {{outlet}} - ` - }, 'it should not have rewritten the template'); - }); + `, + }, + 'it should not have rewritten the template' + ); + } + ); }); QUnit.module('feature:enable template-only-glimmer-components', () => { @@ -364,7 +465,7 @@ QUnit.module('commands', hooks => { const CLASSIC_BEFORE = { components: { 'not-template-only.js': '/* do not touch */', - 'ts-not-template-only.ts': '/* do not touch */' + 'ts-not-template-only.ts': '/* do not touch */', }, templates: { 'not-component.hbs': '', @@ -373,9 +474,9 @@ QUnit.module('commands', hooks => { 'another.hbs': '', 'not-template-only.hbs': '', 'ts-not-template-only.hbs': '', - 'also-not-component.txt': 'This is not a component file.' - } - } + 'also-not-component.txt': 'This is not a component file.', + }, + }, }; const CLASSIC_AFTER = { @@ -383,7 +484,7 @@ QUnit.module('commands', hooks => { 'foo-bar.js': componentJS, 'another.js': componentJS, 'not-template-only.js': '/* do not touch */', - 'ts-not-template-only.ts': '/* do not touch */' + 'ts-not-template-only.ts': '/* do not touch */', }, templates: { 'not-component.hbs': '', @@ -392,9 +493,9 @@ QUnit.module('commands', hooks => { 'another.hbs': '', 'not-template-only.hbs': '', 'ts-not-template-only.hbs': '', - 'also-not-component.txt': 'This is not a component file.' - } - } + 'also-not-component.txt': 'This is not a component file.', + }, + }, }; const PODS_BEFORE = { @@ -403,11 +504,11 @@ QUnit.module('commands', hooks => { 'foo-bar': { 'template.hbs': '', }, - 'another': { + another: { 'template.hbs': '', }, 'also-not-component': { - 'something.txt': 'This is not a component file.' + 'something.txt': 'This is not a component file.', }, 'not-template-only': { 'component.js': '/* do not touch */', @@ -421,7 +522,7 @@ QUnit.module('commands', hooks => { 'not-component': { 'template.hbs': '', }, - } + }, }; const PODS_AFTER = { @@ -431,12 +532,12 @@ QUnit.module('commands', hooks => { 'component.js': componentJS, 'template.hbs': '', }, - 'another': { + another: { 'component.js': componentJS, 'template.hbs': '', }, 'also-not-component': { - 'something.txt': 'This is not a component file.' + 'something.txt': 'This is not a component file.', }, 'not-template-only': { 'component.js': '/* do not touch */', @@ -450,7 +551,7 @@ QUnit.module('commands', hooks => { 'not-component': { 'template.hbs': '', }, - } + }, }; const MIXED_BEFORE = { @@ -524,21 +625,40 @@ QUnit.module('commands', hooks => { }, }; - QUnit.test('it generates component files when asked to', async function (assert) { + QUnit.test('it generates component files when asked to', async function ( + assert + ) { project.write({ app: CLASSIC_BEFORE }); - await run('feature:enable', 'template-only-glimmer-components', { input: 'yes\n' }); + await run('feature:enable', 'template-only-glimmer-components', { + input: 'yes\n', + }); - assert.deepEqual(project.read('app'), CLASSIC_AFTER, 'it should have generated the component JS files'); + assert.deepEqual( + project.read('app'), + CLASSIC_AFTER, + 'it should have generated the component JS files' + ); }); - QUnit.test('it generates component files without prompt when asked to', async function (assert) { - project.write({ app: CLASSIC_BEFORE }); - - await run('feature:enable', 'template-only-glimmer-components', '--run-codemod'); - - assert.deepEqual(project.read('app'), CLASSIC_AFTER, 'it should have generated the component JS files'); - }); + QUnit.test( + 'it generates component files without prompt when asked to', + async function (assert) { + project.write({ app: CLASSIC_BEFORE }); + + await run( + 'feature:enable', + 'template-only-glimmer-components', + '--run-codemod' + ); + + assert.deepEqual( + project.read('app'), + CLASSIC_AFTER, + 'it should have generated the component JS files' + ); + } + ); QUnit.test('it works for pods', async function (assert) { project.write({ @@ -549,13 +669,19 @@ QUnit.module('commands', hooks => { modulePrefix: 'my-app', podModulePrefix: 'my-app/pods', }; - };` - } + };`, + }, }); - await run('feature:enable', 'template-only-glimmer-components', { input: 'yes\n' }); + await run('feature:enable', 'template-only-glimmer-components', { + input: 'yes\n', + }); - assert.deepEqual(project.read('app'), PODS_AFTER, 'it should have generated the component JS files'); + assert.deepEqual( + project.read('app'), + PODS_AFTER, + 'it should have generated the component JS files' + ); }); QUnit.test('it works for mixed layout apps', async function (assert) { @@ -567,38 +693,64 @@ QUnit.module('commands', hooks => { modulePrefix: 'my-app', podModulePrefix: 'my-app/pods', }; - };` - } + };`, + }, }); - await run('feature:enable', 'template-only-glimmer-components', { input: 'yes\n' }); + await run('feature:enable', 'template-only-glimmer-components', { + input: 'yes\n', + }); - assert.deepEqual(project.read('app'), MIXED_AFTER, 'it should have generated the component JS files'); + assert.deepEqual( + project.read('app'), + MIXED_AFTER, + 'it should have generated the component JS files' + ); }); - QUnit.test('it does not generates component files when asked not to', async function (assert) { - project.write({ app: CLASSIC_BEFORE }); + QUnit.test( + 'it does not generates component files when asked not to', + async function (assert) { + project.write({ app: CLASSIC_BEFORE }); - await run('feature:enable', 'template-only-glimmer-components', { input: 'no\n' }); + await run('feature:enable', 'template-only-glimmer-components', { + input: 'no\n', + }); - assert.deepEqual(project.read('app'), CLASSIC_BEFORE, 'it should have generated the component JS files'); - }); + assert.deepEqual( + project.read('app'), + CLASSIC_BEFORE, + 'it should have generated the component JS files' + ); + } + ); - QUnit.test('it fails for missing `modulePrefix` when `podModulePrefix` is set', async function (assert) { - project.write({ - app: PODS_BEFORE, - config: { - 'environment.js': `module.exports = function() { + QUnit.test( + 'it fails for missing `modulePrefix` when `podModulePrefix` is set', + async function (assert) { + project.write({ + app: PODS_BEFORE, + config: { + 'environment.js': `module.exports = function() { return { podModulePrefix: 'my-app/pods', }; - };` - } - }); - - let result = await run('feature:enable', 'template-only-glimmer-components', { input: 'yes\n' }); + };`, + }, + }); - assert.ok(result.stdout.includes('`podModulePrefix` could not be processed correctly')); - }); + let result = await run( + 'feature:enable', + 'template-only-glimmer-components', + { input: 'yes\n' } + ); + + assert.ok( + result.stdout.includes( + '`podModulePrefix` could not be processed correctly' + ) + ); + } + ); }); }); diff --git a/tests/optional-features-test.js b/tests/optional-features-test.js index 9cd6219..5155547 100644 --- a/tests/optional-features-test.js +++ b/tests/optional-features-test.js @@ -8,7 +8,7 @@ function stringify(obj) { return JSON.stringify(obj, null, 2); } -QUnit.module('@ember/optional-features', hooks => { +QUnit.module('@ember/optional-features', (hooks) => { let override, projectRoot; function buildAddon(features) { @@ -16,7 +16,7 @@ QUnit.module('@ember/optional-features', hooks => { projectRoot.write({ config: { 'optional-features.json': stringify(features), - } + }, }); } @@ -28,7 +28,7 @@ QUnit.module('@ember/optional-features', hooks => { hooks.beforeEach(() => { override = process.env.EMBER_OPTIONAL_FEATURES; - return createTempDir().then(tmpDir => { + return createTempDir().then((tmpDir) => { projectRoot = tmpDir; projectRoot.write({ @@ -36,7 +36,7 @@ QUnit.module('@ember/optional-features', hooks => { name: 'test-project', devDependencies: { 'ember-cli': '*', - } + }, }), }); }); @@ -52,105 +52,152 @@ QUnit.module('@ember/optional-features', hooks => { return projectRoot.dispose(); }); - QUnit.test('it throws on invalid key', assert => { + QUnit.test('it throws on invalid key', (assert) => { assert.throws(() => buildAddon({ foo: true }), /Unknown feature "foo"/); }); - QUnit.test('it throws on invalid value', assert => { + QUnit.test('it throws on invalid value', (assert) => { assert.throws( () => buildAddon({ 'application-template-wrapper': 'nope' }), /Unsupported value "nope" for "application-template-wrapper"/ ); }); - QUnit.test('it generates an empty config when features are not passed', assert => { - let addon = buildAddon({}); - assert.deepEqual(addon.config(), { EmberENV: {} }, 'Expecting empty config'); - }); - - QUnit.test('it generates the correct config when features are passed', assert => { - let addon = buildAddon({ - 'application-template-wrapper': false, - 'template-only-glimmer-components': true, - 'jquery-integration': true - }); - - let expected = { - EmberENV: { - "_APPLICATION_TEMPLATE_WRAPPER": false, - "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true, - "_JQUERY_INTEGRATION": true - } - }; + QUnit.test( + 'it generates an empty config when features are not passed', + (assert) => { + let addon = buildAddon({}); + assert.deepEqual( + addon.config(), + { EmberENV: {} }, + 'Expecting empty config' + ); + } + ); + + QUnit.test( + 'it generates the correct config when features are passed', + (assert) => { + let addon = buildAddon({ + 'application-template-wrapper': false, + 'template-only-glimmer-components': true, + 'jquery-integration': true, + }); - assert.deepEqual(addon.config(), expected, 'Expecting correct config'); - }); + let expected = { + EmberENV: { + _APPLICATION_TEMPLATE_WRAPPER: false, + _TEMPLATE_ONLY_GLIMMER_COMPONENTS: true, + _JQUERY_INTEGRATION: true, + }, + }; - QUnit.test('it does not remove features that matches their default value', assert => { - let addon = buildAddon({ - 'application-template-wrapper': true, - 'template-only-glimmer-components': true, - 'jquery-integration': true - }); + assert.deepEqual(addon.config(), expected, 'Expecting correct config'); + } + ); + + QUnit.test( + 'it does not remove features that matches their default value', + (assert) => { + let addon = buildAddon({ + 'application-template-wrapper': true, + 'template-only-glimmer-components': true, + 'jquery-integration': true, + }); - let expected = { - EmberENV: { - "_APPLICATION_TEMPLATE_WRAPPER": true, - "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true, - "_JQUERY_INTEGRATION": true - } - }; + let expected = { + EmberENV: { + _APPLICATION_TEMPLATE_WRAPPER: true, + _TEMPLATE_ONLY_GLIMMER_COMPONENTS: true, + _JQUERY_INTEGRATION: true, + }, + }; - assert.deepEqual(addon.config(), expected, 'Expecting correct config'); - }); + assert.deepEqual(addon.config(), expected, 'Expecting correct config'); + } + ); - QUnit.test('it allows `null` to mean using the default value', assert => { + QUnit.test('it allows `null` to mean using the default value', (assert) => { let addon = buildAddon({ 'application-template-wrapper': null, 'template-only-glimmer-components': null, - 'jquery-integration': null + 'jquery-integration': null, }); let expected = { - EmberENV: {} + EmberENV: {}, }; assert.deepEqual(addon.config(), expected, 'Expecting correct config'); }); - QUnit.test('it can query the features with `isFeatureEnabled`', assert => { + QUnit.test('it can query the features with `isFeatureEnabled`', (assert) => { let addon = buildAddon({ - 'application-template-wrapper': false + 'application-template-wrapper': false, }); - assert.strictEqual(addon.isFeatureEnabled('application-template-wrapper'), false, 'Expecting suppied value'); - assert.strictEqual(addon.isFeatureEnabled('template-only-glimmer-components'), false, 'Expecting default value'); + assert.strictEqual( + addon.isFeatureEnabled('application-template-wrapper'), + false, + 'Expecting suppied value' + ); + assert.strictEqual( + addon.isFeatureEnabled('template-only-glimmer-components'), + false, + 'Expecting default value' + ); }); - QUnit.test('it can query the features with `isFeatureExplicitlySet`', assert => { - let addon = buildAddon({ - 'application-template-wrapper': false - }); + QUnit.test( + 'it can query the features with `isFeatureExplicitlySet`', + (assert) => { + let addon = buildAddon({ + 'application-template-wrapper': false, + }); - assert.strictEqual(addon.isFeatureExplicitlySet('application-template-wrapper'), true, 'Expecting value to exist'); - assert.strictEqual(addon.isFeatureExplicitlySet('template-only-glimmer-components'), false, 'Expecting to not exist'); - }); + assert.strictEqual( + addon.isFeatureExplicitlySet('application-template-wrapper'), + true, + 'Expecting value to exist' + ); + assert.strictEqual( + addon.isFeatureExplicitlySet('template-only-glimmer-components'), + false, + 'Expecting to not exist' + ); + } + ); - QUnit.test('it allows the config to be a overridden with an ENV variable', assert => { - process.env.EMBER_OPTIONAL_FEATURES = `{ "application-template-wrapper": false }`; + QUnit.test( + 'it allows the config to be a overridden with an ENV variable', + (assert) => { + process.env.EMBER_OPTIONAL_FEATURES = `{ "application-template-wrapper": false }`; - let addon = buildAddon({ - 'application-template-wrapper': true, - 'template-only-glimmer-components': true, - 'jquery-integration': true - }); + let addon = buildAddon({ + 'application-template-wrapper': true, + 'template-only-glimmer-components': true, + 'jquery-integration': true, + }); - assert.strictEqual(addon.isFeatureEnabled('application-template-wrapper'), false, 'Expecting value from ENV var'); - assert.strictEqual(addon.isFeatureEnabled('template-only-glimmer-components'), true, 'Expecting value from JSON'); - assert.strictEqual(addon.isFeatureEnabled('jquery-integration'), true, 'Expecting value from JSON'); - }); + assert.strictEqual( + addon.isFeatureEnabled('application-template-wrapper'), + false, + 'Expecting value from ENV var' + ); + assert.strictEqual( + addon.isFeatureEnabled('template-only-glimmer-components'), + true, + 'Expecting value from JSON' + ); + assert.strictEqual( + addon.isFeatureEnabled('jquery-integration'), + true, + 'Expecting value from JSON' + ); + } + ); - QUnit.test('can provide custom config path', assert => { + QUnit.test('can provide custom config path', (assert) => { projectRoot.write({ 'package.json': stringify({ name: 'test-project', @@ -159,7 +206,7 @@ QUnit.module('@ember/optional-features', hooks => { }, 'ember-addon': { configPath: 'tests/dummy/config', - } + }, }), tests: { dummy: { @@ -167,21 +214,21 @@ QUnit.module('@ember/optional-features', hooks => { 'optional-features.json': stringify({ 'application-template-wrapper': false, 'template-only-glimmer-components': true, - 'jquery-integration': true + 'jquery-integration': true, }), - } - } - } + }, + }, + }, }); let addon = buildAddon(); let expected = { EmberENV: { - "_APPLICATION_TEMPLATE_WRAPPER": false, - "_TEMPLATE_ONLY_GLIMMER_COMPONENTS": true, - "_JQUERY_INTEGRATION": true - } + _APPLICATION_TEMPLATE_WRAPPER: false, + _TEMPLATE_ONLY_GLIMMER_COMPONENTS: true, + _JQUERY_INTEGRATION: true, + }, }; assert.deepEqual(addon.config(), expected, 'Expecting correct config'); diff --git a/tests/utils-test.js b/tests/utils-test.js index ef769df..d3d9243 100644 --- a/tests/utils-test.js +++ b/tests/utils-test.js @@ -5,37 +5,47 @@ const join = utils.join; const strip = utils.strip; QUnit.module('utils', () => { - QUnit.test('join', assert => { + QUnit.test('join', (assert) => { assert.equal(join``, ``); assert.equal(join`hello world`, `hello world`); - assert.equal(join`h${"E"}l${"L"}o${" "}w${"O"}r${"L"}d`, `h${"E"}l${"L"}o${" "}w${"O"}r${"L"}d`); - assert.equal(join` + assert.equal( + join`h${'E'}l${'L'}o${' '}w${'O'}r${'L'}d`, + `h${'E'}l${'L'}o${' '}w${'O'}r${'L'}d` + ); + assert.equal( + join` wow - ${"such"} + ${'such'} very - ${"amaze"}`, ` + ${'amaze'}`, + ` wow - ${"such"} + ${'such'} very - ${"amaze"}`); + ${'amaze'}` + ); }); - QUnit.test('strip', assert => { + QUnit.test('strip', (assert) => { assert.equal(strip``, ``); assert.equal(strip`hello world`, `hello world`); - assert.equal(strip`h${"E"}l${"L"}o${" "}w${"O"}r${"L"}d`, `h${"E"}l${"L"}o${" "}w${"O"}r${"L"}d`); + assert.equal( + strip`h${'E'}l${'L'}o${' '}w${'O'}r${'L'}d`, + `h${'E'}l${'L'}o${' '}w${'O'}r${'L'}d` + ); assert.equal(strip`\n`, ''); assert.equal(strip` \n `, '\n'); assert.equal(strip` `, ''); - assert.equal(strip` + assert.equal( + strip` @@ -58,25 +68,25 @@ very `, '\n' + - '\n' + - ' \n' + - ' Hello world\n' + - ' \n' + - ' \n' + - '

        Hello world

        \n' + - '\n' + - '
        \n' +
        -      '  wow\n' +
        -      '\n' +
        -      '     such\n' +
        -      '\n' +
        -      'very\n' +
        -      '\n' +
        -      '    amaze\n' +
        -      '    
        \n' + - '\n' + - ' \n' + - '\n' + '\n' + + ' \n' + + ' Hello world\n' + + ' \n' + + ' \n' + + '

        Hello world

        \n' + + '\n' + + '
        \n' +
        +        '  wow\n' +
        +        '\n' +
        +        '     such\n' +
        +        '\n' +
        +        'very\n' +
        +        '\n' +
        +        '    amaze\n' +
        +        '    
        \n' + + '\n' + + ' \n' + + '\n' ); }); }); diff --git a/utils.js b/utils.js index dcf8bdb..eba8786 100644 --- a/utils.js +++ b/utils.js @@ -13,11 +13,11 @@ function getConfigPath(project) { function join(strings /*, ...args */) { let parts = []; - for (let i=0; i line.replace(indent, '')).join('\n'); + return lines.map((line) => line.replace(indent, '')).join('\n'); } module.exports = { getConfigPath, join, - strip + strip, };