webpacker 5.2.1 → 6.0.0.pre.1

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 (154) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +1 -1
  3. data/.gitignore +2 -0
  4. data/.node-version +1 -1
  5. data/.rubocop.yml +11 -16
  6. data/CHANGELOG.md +15 -4
  7. data/CONTRIBUTING.md +1 -1
  8. data/Gemfile.lock +17 -11
  9. data/README.md +8 -4
  10. data/docs/assets.md +21 -5
  11. data/docs/css.md +24 -29
  12. data/docs/deployment.md +18 -0
  13. data/docs/docker.md +2 -2
  14. data/docs/engines.md +1 -1
  15. data/docs/env.md +5 -0
  16. data/docs/es6.md +1 -1
  17. data/docs/integrations.md +1 -1
  18. data/docs/props.md +2 -38
  19. data/docs/react.md +183 -0
  20. data/docs/testing.md +11 -0
  21. data/docs/typescript.md +2 -2
  22. data/docs/webpack-dev-server.md +17 -15
  23. data/docs/webpack.md +58 -107
  24. data/lib/install/config/webpack/base.js +3 -0
  25. data/lib/install/config/webpack/development.js +2 -2
  26. data/lib/install/config/webpack/production.js +2 -2
  27. data/lib/install/config/webpack/test.js +2 -2
  28. data/lib/install/config/webpacker.yml +8 -37
  29. data/lib/install/examples/{vue → vue3}/app.vue +10 -5
  30. data/lib/install/examples/vue3/hello_vue.js +15 -0
  31. data/lib/install/javascript/packs/application.css +9 -0
  32. data/lib/install/template.rb +33 -19
  33. data/lib/tasks/webpacker.rake +2 -11
  34. data/lib/tasks/webpacker/binstubs.rake +6 -4
  35. data/lib/tasks/webpacker/check_binstubs.rake +4 -4
  36. data/lib/tasks/webpacker/check_yarn.rake +1 -2
  37. data/lib/tasks/webpacker/compile.rake +4 -2
  38. data/lib/tasks/webpacker/info.rake +12 -10
  39. data/lib/tasks/webpacker/install.rake +6 -4
  40. data/lib/tasks/webpacker/verify_install.rake +2 -1
  41. data/lib/tasks/webpacker/yarn_install.rake +9 -1
  42. data/lib/webpacker/commands.rb +1 -1
  43. data/lib/webpacker/compiler.rb +7 -6
  44. data/lib/webpacker/configuration.rb +6 -30
  45. data/lib/webpacker/dev_server_runner.rb +21 -2
  46. data/lib/webpacker/helper.rb +22 -32
  47. data/lib/webpacker/manifest.rb +1 -1
  48. data/lib/webpacker/version.rb +1 -1
  49. data/lib/webpacker/webpack_runner.rb +5 -0
  50. data/package.json +23 -39
  51. data/package/__tests__/config.js +5 -37
  52. data/package/__tests__/development.js +9 -11
  53. data/package/__tests__/env.js +12 -4
  54. data/package/__tests__/production.js +6 -6
  55. data/package/__tests__/staging.js +7 -6
  56. data/package/__tests__/test.js +4 -5
  57. data/package/babel/preset-react.js +62 -0
  58. data/package/babel/preset.js +44 -0
  59. data/package/config.js +3 -11
  60. data/package/env.js +8 -2
  61. data/package/environments/__tests__/base.js +15 -47
  62. data/package/environments/base.js +66 -126
  63. data/package/environments/development.js +45 -44
  64. data/package/environments/production.js +69 -65
  65. data/package/environments/test.js +2 -2
  66. data/package/index.js +6 -6
  67. data/package/rules/babel.js +9 -7
  68. data/package/rules/coffee.js +6 -0
  69. data/package/rules/erb.js +13 -0
  70. data/package/rules/file.js +19 -19
  71. data/package/rules/index.js +24 -18
  72. data/package/rules/less.js +18 -0
  73. data/package/rules/sass.js +5 -6
  74. data/package/rules/svg.js +23 -0
  75. data/package/utils/get_style_rule.js +22 -28
  76. data/package/utils/helpers.js +3 -35
  77. data/test/compiler_test.rb +0 -12
  78. data/test/configuration_test.rb +1 -32
  79. data/test/dev_server_runner_test.rb +24 -5
  80. data/test/engine_rake_tasks_test.rb +39 -0
  81. data/test/helper_test.rb +15 -9
  82. data/test/mounted_app/Rakefile +4 -0
  83. data/test/mounted_app/test/dummy/Rakefile +3 -0
  84. data/test/mounted_app/test/dummy/bin/rails +3 -0
  85. data/test/mounted_app/test/dummy/bin/rake +3 -0
  86. data/test/mounted_app/test/dummy/config.ru +5 -0
  87. data/test/mounted_app/test/dummy/config/application.rb +10 -0
  88. data/test/mounted_app/test/dummy/config/environment.rb +3 -0
  89. data/test/mounted_app/test/dummy/config/webpacker.yml +75 -0
  90. data/test/mounted_app/test/dummy/package.json +7 -0
  91. data/test/rake_tasks_test.rb +1 -10
  92. data/test/test_app/config/webpacker.yml +1 -25
  93. data/test/test_app/config/webpacker_public_root.yml +0 -1
  94. data/test/test_app/public/packs/manifest.json +17 -13
  95. data/test/test_app/some.config.js +0 -0
  96. data/test/webpack_runner_test.rb +9 -3
  97. data/webpacker.gemspec +1 -1
  98. data/yarn.lock +1858 -4915
  99. metadata +47 -70
  100. data/.travis.yml +0 -43
  101. data/lib/install/angular.rb +0 -23
  102. data/lib/install/coffee.rb +0 -25
  103. data/lib/install/config/.browserslistrc +0 -1
  104. data/lib/install/config/babel.config.js +0 -70
  105. data/lib/install/config/postcss.config.js +0 -12
  106. data/lib/install/config/webpack/environment.js +0 -3
  107. data/lib/install/elm.rb +0 -39
  108. data/lib/install/erb.rb +0 -25
  109. data/lib/install/examples/angular/hello_angular.js +0 -7
  110. data/lib/install/examples/angular/hello_angular/app/app.component.ts +0 -9
  111. data/lib/install/examples/angular/hello_angular/app/app.module.ts +0 -16
  112. data/lib/install/examples/angular/hello_angular/index.ts +0 -8
  113. data/lib/install/examples/angular/hello_angular/polyfills.ts +0 -73
  114. data/lib/install/examples/coffee/hello_coffee.coffee +0 -4
  115. data/lib/install/examples/elm/Main.elm +0 -55
  116. data/lib/install/examples/elm/hello_elm.js +0 -16
  117. data/lib/install/examples/erb/hello_erb.js.erb +0 -6
  118. data/lib/install/examples/react/babel.config.js +0 -87
  119. data/lib/install/examples/react/hello_react.jsx +0 -26
  120. data/lib/install/examples/react/tsconfig.json +0 -21
  121. data/lib/install/examples/stimulus/application.js +0 -1
  122. data/lib/install/examples/stimulus/controllers/hello_controller.js +0 -18
  123. data/lib/install/examples/stimulus/controllers/index.js +0 -9
  124. data/lib/install/examples/svelte/app.svelte +0 -11
  125. data/lib/install/examples/svelte/hello_svelte.js +0 -20
  126. data/lib/install/examples/typescript/hello_typescript.ts +0 -4
  127. data/lib/install/examples/typescript/tsconfig.json +0 -24
  128. data/lib/install/examples/vue/hello_vue.js +0 -72
  129. data/lib/install/loaders/coffee.js +0 -6
  130. data/lib/install/loaders/elm.js +0 -25
  131. data/lib/install/loaders/erb.js +0 -11
  132. data/lib/install/loaders/svelte.js +0 -9
  133. data/lib/install/loaders/vue.js +0 -6
  134. data/lib/install/react.rb +0 -18
  135. data/lib/install/stimulus.rb +0 -12
  136. data/lib/install/svelte.rb +0 -29
  137. data/lib/install/typescript.rb +0 -39
  138. data/lib/install/vue.rb +0 -49
  139. data/lib/tasks/installers.rake +0 -42
  140. data/package/config_types/__tests__/config_list.js +0 -118
  141. data/package/config_types/__tests__/config_object.js +0 -43
  142. data/package/config_types/config_list.js +0 -75
  143. data/package/config_types/config_object.js +0 -55
  144. data/package/config_types/index.js +0 -7
  145. data/package/rules/module.css.js +0 -3
  146. data/package/rules/module.sass.js +0 -8
  147. data/package/rules/node_modules.js +0 -22
  148. data/package/utils/__tests__/deep_assign.js +0 -32
  149. data/package/utils/__tests__/deep_merge.js +0 -10
  150. data/package/utils/__tests__/get_style_rule.js +0 -65
  151. data/package/utils/__tests__/objectify.js +0 -9
  152. data/package/utils/deep_assign.js +0 -22
  153. data/package/utils/deep_merge.js +0 -22
  154. data/package/utils/objectify.js +0 -3
@@ -1,24 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "declaration": false,
4
- "emitDecoratorMetadata": true,
5
- "experimentalDecorators": true,
6
- "lib": ["es6", "dom"],
7
- "module": "es6",
8
- "moduleResolution": "node",
9
- "baseUrl": ".",
10
- "paths": {
11
- "*": ["node_modules/*", "app/javascript/*"]
12
- },
13
- "sourceMap": true,
14
- "target": "es5",
15
- "noEmit": true
16
- },
17
- "exclude": [
18
- "**/*.spec.ts",
19
- "node_modules",
20
- "vendor",
21
- "public"
22
- ],
23
- "compileOnSave": false
24
- }
@@ -1,72 +0,0 @@
1
- /* eslint no-console: 0 */
2
- // Run this example by adding <%= javascript_pack_tag 'hello_vue' %> (and
3
- // <%= stylesheet_pack_tag 'hello_vue' %> if you have styles in your component)
4
- // to the head of your layout file,
5
- // like app/views/layouts/application.html.erb.
6
- // All it does is render <div>Hello Vue</div> at the bottom of the page.
7
-
8
- import Vue from 'vue'
9
- import App from '../app.vue'
10
-
11
- document.addEventListener('DOMContentLoaded', () => {
12
- const app = new Vue({
13
- render: h => h(App)
14
- }).$mount()
15
- document.body.appendChild(app.$el)
16
-
17
- console.log(app)
18
- })
19
-
20
-
21
- // The above code uses Vue without the compiler, which means you cannot
22
- // use Vue to target elements in your existing html templates. You would
23
- // need to always use single file components.
24
- // To be able to target elements in your existing html/erb templates,
25
- // comment out the above code and uncomment the below
26
- // Add <%= javascript_pack_tag 'hello_vue' %> to your layout
27
- // Then add this markup to your html template:
28
- //
29
- // <div id='hello'>
30
- // {{message}}
31
- // <app></app>
32
- // </div>
33
-
34
-
35
- // import Vue from 'vue/dist/vue.esm'
36
- // import App from '../app.vue'
37
- //
38
- // document.addEventListener('DOMContentLoaded', () => {
39
- // const app = new Vue({
40
- // el: '#hello',
41
- // data: {
42
- // message: "Can you say hello?"
43
- // },
44
- // components: { App }
45
- // })
46
- // })
47
- //
48
- //
49
- //
50
- // If the project is using turbolinks, install 'vue-turbolinks':
51
- //
52
- // yarn add vue-turbolinks
53
- //
54
- // Then uncomment the code block below:
55
- //
56
- // import TurbolinksAdapter from 'vue-turbolinks'
57
- // import Vue from 'vue/dist/vue.esm'
58
- // import App from '../app.vue'
59
- //
60
- // Vue.use(TurbolinksAdapter)
61
- //
62
- // document.addEventListener('turbolinks:load', () => {
63
- // const app = new Vue({
64
- // el: '#hello',
65
- // data: () => {
66
- // return {
67
- // message: "Can you say hello?"
68
- // }
69
- // },
70
- // components: { App }
71
- // })
72
- // })
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- test: /\.coffee(\.erb)?$/,
3
- use: [{
4
- loader: 'coffee-loader'
5
- }]
6
- }
@@ -1,25 +0,0 @@
1
- const { resolve } = require('path')
2
-
3
- const isProduction = process.env.NODE_ENV === 'production'
4
- const isDevelopment = process.env.NODE_ENV === 'development'
5
- const elmSource = resolve(process.cwd())
6
- const elmBinary = `${elmSource}/node_modules/.bin/elm`
7
-
8
- const options = {
9
- cwd: elmSource,
10
- pathToElm: elmBinary,
11
- optimize: isProduction,
12
- verbose: isDevelopment,
13
- debug: isDevelopment
14
- }
15
-
16
- const elmWebpackLoader = {
17
- loader: 'elm-webpack-loader',
18
- options: options
19
- }
20
-
21
- module.exports = {
22
- test: /\.elm(\.erb)?$/,
23
- exclude: [/elm-stuff/, /node_modules/],
24
- use: isProduction ? [elmWebpackLoader] : [{ loader: 'elm-hot-webpack-loader' }, elmWebpackLoader]
25
- }
@@ -1,11 +0,0 @@
1
- module.exports = {
2
- test: /\.erb$/,
3
- enforce: 'pre',
4
- exclude: /node_modules/,
5
- use: [{
6
- loader: 'rails-erb-loader',
7
- options: {
8
- runner: (/^win/.test(process.platform) ? 'ruby ' : '') + 'bin/rails runner'
9
- }
10
- }]
11
- }
@@ -1,9 +0,0 @@
1
- module.exports = {
2
- test: /\.svelte(\.erb)?$/,
3
- use: [{
4
- loader: 'svelte-loader',
5
- options: {
6
- hotReload: false
7
- }
8
- }],
9
- }
@@ -1,6 +0,0 @@
1
- module.exports = {
2
- test: /\.vue(\.erb)?$/,
3
- use: [{
4
- loader: 'vue-loader'
5
- }]
6
- }
@@ -1,18 +0,0 @@
1
- require "webpacker/configuration"
2
- require "fileutils"
3
-
4
- replace_babel_config = FileUtils.compare_file(Rails.root.join("babel.config.js"), "#{__dir__}/config/babel.config.js")
5
-
6
- say "Copying babel.config.js to app root directory"
7
- copy_file "#{__dir__}/examples/react/babel.config.js", "babel.config.js", force: replace_babel_config
8
-
9
- say "Copying react example entry file to #{Webpacker.config.source_entry_path}"
10
- copy_file "#{__dir__}/examples/react/hello_react.jsx", "#{Webpacker.config.source_entry_path}/hello_react.jsx"
11
-
12
- say "Updating webpack paths to include .jsx file extension"
13
- insert_into_file Webpacker.config.config_path, "- .jsx\n".indent(4), after: /\s+extensions:\n/
14
-
15
- say "Installing all react dependencies"
16
- run "yarn add react react-dom @babel/preset-react prop-types babel-plugin-transform-react-remove-prop-types"
17
-
18
- say "Webpacker now supports react.js 🎉", :green
@@ -1,12 +0,0 @@
1
- say "Appending Stimulus setup code to #{Webpacker.config.source_entry_path}/application.js"
2
- append_to_file "#{Webpacker.config.source_entry_path}/application.js" do
3
- "\n" + open("#{__dir__}/examples/stimulus/application.js").read
4
- end
5
-
6
- say "Creating controllers directory"
7
- directory "#{__dir__}/examples/stimulus/controllers", "#{Webpacker.config.source_path}/controllers"
8
-
9
- say "Installing all Stimulus dependencies"
10
- run "yarn add stimulus"
11
-
12
- say "Webpacker now supports Stimulus.js 🎉", :green
@@ -1,29 +0,0 @@
1
- require "webpacker/configuration"
2
-
3
- say "Copying svelte loader to config/webpack/loaders"
4
- copy_file "#{__dir__}/loaders/svelte.js", Rails.root.join("config/webpack/loaders/svelte.js").to_s
5
-
6
- say "Adding svelte loader to config/webpack/environment.js"
7
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
- "const svelte = require('./loaders/svelte')\n",
9
- after: /require\(('|")@rails\/webpacker\1\);?\n/
10
-
11
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
- "environment.loaders.prepend('svelte', svelte)\n",
13
- before: "module.exports"
14
-
15
- say "Copying Svelte example entry file to #{Webpacker.config.source_entry_path}"
16
- copy_file "#{__dir__}/examples/svelte/hello_svelte.js",
17
- "#{Webpacker.config.source_entry_path}/hello_svelte.js"
18
-
19
- say "Copying Svelte app file to #{Webpacker.config.source_path}"
20
- copy_file "#{__dir__}/examples/svelte/app.svelte",
21
- "#{Webpacker.config.source_path}/app.svelte"
22
-
23
- say "Installing all Svelte dependencies"
24
- run "yarn add svelte svelte-loader"
25
-
26
- say "Updating webpack paths to include .svelte file extension"
27
- insert_into_file Webpacker.config.config_path, "- .svelte\n".indent(4), after: /\s+extensions:\n/
28
-
29
- say "Webpacker now supports Svelte 🎉", :green
@@ -1,39 +0,0 @@
1
- require "webpacker/configuration"
2
-
3
- additional_packages = ""
4
- example_source = "typescript"
5
-
6
- # Additional configuration is required for React projects
7
- package_json = Rails.root.join("package.json")
8
- if File.exist?(package_json)
9
- package = JSON.parse(File.read(package_json))
10
- package["dependencies"] ||= {}
11
-
12
- if package["dependencies"].keys.include?("react")
13
- additional_packages = "@types/react @types/react-dom"
14
- example_source = "react"
15
- end
16
- end
17
-
18
- say "Adding TypeScript preset to babel.config.js"
19
- insert_into_file Rails.root.join("babel.config.js").to_s,
20
- ",\n ['@babel/preset-typescript', { 'allExtensions': true, 'isTSX': true }]",
21
- before: /\s*\].filter\(Boolean\),\n\s*plugins: \[/
22
-
23
- say "Copying tsconfig.json to the Rails root directory for typescript"
24
- copy_file "#{__dir__}/examples/#{example_source}/tsconfig.json", "tsconfig.json"
25
-
26
- say "Updating webpack paths to include .ts file extension"
27
- insert_into_file Webpacker.config.config_path, "- .ts\n".indent(4), after: /\s+extensions:\n/
28
-
29
- say "Updating webpack paths to include .tsx file extension"
30
- insert_into_file Webpacker.config.config_path, "- .tsx\n".indent(4), after: /\s+extensions:\n/
31
-
32
- say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
33
- copy_file "#{__dir__}/examples/typescript/hello_typescript.ts",
34
- "#{Webpacker.config.source_entry_path}/hello_typescript.ts"
35
-
36
- say "Installing all typescript dependencies"
37
- run "yarn add typescript @babel/preset-typescript #{additional_packages}"
38
-
39
- say "Webpacker now supports typescript 🎉", :green
@@ -1,49 +0,0 @@
1
- require "webpacker/configuration"
2
-
3
- say "Copying vue loader to config/webpack/loaders"
4
- copy_file "#{__dir__}/loaders/vue.js", Rails.root.join("config/webpack/loaders/vue.js").to_s
5
-
6
- say "Adding vue loader plugin to config/webpack/environment.js"
7
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
8
- "const { VueLoaderPlugin } = require('vue-loader')\n",
9
- after: /require\(('|")@rails\/webpacker\1\);?\n/
10
-
11
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
12
- "environment.plugins.prepend('VueLoaderPlugin', new VueLoaderPlugin())\n",
13
- before: "module.exports"
14
-
15
- say "Adding vue loader to config/webpack/environment.js"
16
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
17
- "const vue = require('./loaders/vue')\n",
18
- after: "require('vue-loader')\n"
19
-
20
- insert_into_file Rails.root.join("config/webpack/environment.js").to_s,
21
- "environment.loaders.prepend('vue', vue)\n",
22
- before: "module.exports"
23
-
24
- say "Updating webpack paths to include .vue file extension"
25
- insert_into_file Webpacker.config.config_path, "- .vue\n".indent(4), after: /\s+extensions:\n/
26
-
27
- say "Copying the example entry file to #{Webpacker.config.source_entry_path}"
28
- copy_file "#{__dir__}/examples/vue/hello_vue.js",
29
- "#{Webpacker.config.source_entry_path}/hello_vue.js"
30
-
31
- say "Copying Vue app file to #{Webpacker.config.source_entry_path}"
32
- copy_file "#{__dir__}/examples/vue/app.vue",
33
- "#{Webpacker.config.source_path}/app.vue"
34
-
35
- say "Installing all Vue dependencies"
36
- run "yarn add vue vue-loader vue-template-compiler"
37
-
38
- if Rails::VERSION::MAJOR == 5 && Rails::VERSION::MINOR > 1
39
- say "You need to enable unsafe-eval rule.", :yellow
40
- say "This can be done in Rails 5.2+ for development environment in the CSP initializer", :yellow
41
- say "config/initializers/content_security_policy.rb with a snippet like this:", :yellow
42
- say "if Rails.env.development?", :yellow
43
- say " policy.script_src :self, :https, :unsafe_eval", :yellow
44
- say "else", :yellow
45
- say " policy.script_src :self, :https", :yellow
46
- say "end", :yellow
47
- end
48
-
49
- say "Webpacker now supports Vue.js 🎉", :green
@@ -1,42 +0,0 @@
1
- installers = {
2
- "Angular": :angular,
3
- "Elm": :elm,
4
- "React": :react,
5
- "Vue": :vue,
6
- "Erb": :erb,
7
- "Coffee": :coffee,
8
- "Typescript": :typescript,
9
- "Svelte": :svelte,
10
- "Stimulus": :stimulus
11
- }.freeze
12
-
13
- dependencies = {
14
- "Angular": [:typescript]
15
- }
16
-
17
- bin_path = ENV["BUNDLE_BIN"] || "./bin"
18
-
19
- namespace :webpacker do
20
- namespace :install do
21
- installers.each do |name, task_name|
22
- desc "Install everything needed for #{name}"
23
- task task_name => ["webpacker:verify_install"] do
24
- template = File.expand_path("../install/#{task_name}.rb", __dir__)
25
- base_path =
26
- if Rails::VERSION::MAJOR >= 5
27
- "#{RbConfig.ruby} #{bin_path}/rails app:template"
28
- else
29
- "#{RbConfig.ruby} #{bin_path}/rake rails:template"
30
- end
31
-
32
- dependencies[name] ||= []
33
- dependencies[name].each do |dependency|
34
- dependency_template = File.expand_path("../install/#{dependency}.rb", __dir__)
35
- system "#{base_path} LOCATION=#{dependency_template}"
36
- end
37
-
38
- exec "#{base_path} LOCATION=#{template}"
39
- end
40
- end
41
- end
42
- end
@@ -1,118 +0,0 @@
1
- /* global test expect */
2
-
3
- const ConfigList = require('../config_list')
4
-
5
- test('new', () => {
6
- const list = new ConfigList()
7
- expect(list).toBeInstanceOf(ConfigList)
8
- expect(list).toBeInstanceOf(Array)
9
- })
10
-
11
- test('get', () => {
12
- const list = new ConfigList()
13
- list.append('key', 'value')
14
- expect(list.get('key')).toEqual('value')
15
- })
16
-
17
- test('append', () => {
18
- const list = new ConfigList()
19
- list.append('key', 'value')
20
- expect(list.append('key1', 'value1')).toEqual([
21
- { key: 'key', value: 'value' },
22
- { key: 'key1', value: 'value1' }
23
- ])
24
- })
25
-
26
- test('prepend', () => {
27
- const list = new ConfigList()
28
- list.append('key', 'value')
29
- expect(list.prepend('key1', 'value1')).toEqual([
30
- { key: 'key1', value: 'value1' },
31
- { key: 'key', value: 'value' }
32
- ])
33
- })
34
-
35
- test('insert without position', () => {
36
- const list = new ConfigList()
37
- list.append('key', 'value')
38
-
39
- expect(list.insert('key1', 'value1')).toEqual([
40
- { key: 'key', value: 'value' },
41
- { key: 'key1', value: 'value1' }
42
- ])
43
-
44
- expect(list.insert('key2', 'value2')).toEqual([
45
- { key: 'key', value: 'value' },
46
- { key: 'key1', value: 'value1' },
47
- { key: 'key2', value: 'value2' }
48
- ])
49
- })
50
-
51
- test('insert before an item', () => {
52
- const list = new ConfigList()
53
- list.append('key', 'value')
54
- list.append('key1', 'value1')
55
-
56
- expect(list.insert('key2', 'value2', { before: 'key' })).toEqual([
57
- { key: 'key2', value: 'value2' },
58
- { key: 'key', value: 'value' },
59
- { key: 'key1', value: 'value1' }
60
- ])
61
-
62
- expect(list.insert('key3', 'value3', { before: 'key2' })).toEqual([
63
- { key: 'key3', value: 'value3' },
64
- { key: 'key2', value: 'value2' },
65
- { key: 'key', value: 'value' },
66
- { key: 'key1', value: 'value1' }
67
- ])
68
- })
69
-
70
- test('insert after an item', () => {
71
- const list = new ConfigList()
72
- list.append('key', 'value')
73
- list.append('key1', 'value1')
74
-
75
- expect(list.insert('key2', 'value2', { after: 'key' })).toEqual([
76
- { key: 'key', value: 'value' },
77
- { key: 'key2', value: 'value2' },
78
- { key: 'key1', value: 'value1' }
79
- ])
80
-
81
- expect(list.insert('key3', 'value3', { after: 'key2' })).toEqual([
82
- { key: 'key', value: 'value' },
83
- { key: 'key2', value: 'value2' },
84
- { key: 'key3', value: 'value3' },
85
- { key: 'key1', value: 'value1' }
86
- ])
87
- })
88
-
89
- test('delete', () => {
90
- const list = new ConfigList()
91
- list.append('key', 'value')
92
- list.append('key1', 'value1')
93
- expect(list.delete('key')).toEqual([{ key: 'key1', value: 'value1' }])
94
- expect(list.delete('key1')).toEqual([])
95
- })
96
-
97
- test('getIndex', () => {
98
- const list = new ConfigList()
99
- list.append('key', 'value')
100
- list.append('key1', 'value1')
101
- expect(list.getIndex('key')).toEqual(0)
102
- expect(list.getIndex('key2')).toEqual(-1)
103
- expect(() => list.getIndex('key2', true)).toThrow('Item key2 not found')
104
- })
105
-
106
- test('values', () => {
107
- const list = new ConfigList()
108
- list.append('key', 'value')
109
- list.append('key1', 'value1')
110
- expect(list.values()).toEqual(['value', 'value1'])
111
- })
112
-
113
- test('keys', () => {
114
- const list = new ConfigList()
115
- list.append('key', 'value')
116
- list.append('key1', 'value1')
117
- expect(list.keys()).toEqual(['key', 'key1'])
118
- })