DEV: Restore the documentation format in system tests (#21471)

This commit is contained in:
Jarek Radosz 2023-05-12 11:13:52 +02:00 committed by GitHub
parent 177651fdbb
commit 19ac90536f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 75 additions and 15 deletions

View File

@ -180,7 +180,7 @@ jobs:
- name: Plugin RSpec - name: Plugin RSpec
if: matrix.build_type == 'backend' && matrix.target == 'plugins' if: matrix.build_type == 'backend' && matrix.target == 'plugins'
run: bin/rake plugin:turbo_spec run: bin/rake plugin:turbo_spec['*','--verbose --format documentation']
- name: Plugin QUnit - name: Plugin QUnit
if: matrix.build_type == 'frontend' && matrix.target == 'plugins' if: matrix.build_type == 'frontend' && matrix.target == 'plugins'
@ -197,11 +197,11 @@ jobs:
- name: Core System Tests - name: Core System Tests
if: matrix.build_type == 'system' && matrix.target == 'core' if: matrix.build_type == 'system' && matrix.target == 'core'
run: PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --verbose spec/system run: PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --verbose --format documentation spec/system
- name: Plugin System Tests - name: Plugin System Tests
if: matrix.build_type == 'system' && matrix.target == 'plugins' if: matrix.build_type == 'system' && matrix.target == 'plugins'
run: LOAD_PLUGINS=1 PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --verbose plugins/*/spec/system run: LOAD_PLUGINS=1 PARALLEL_TEST_PROCESSORS=4 bin/turbo_rspec --verbose --format documentation plugins/*/spec/system
timeout-minutes: 30 timeout-minutes: 30
- name: Upload failed system test screenshots - name: Upload failed system test screenshots

View File

@ -16,7 +16,7 @@ def generate_chat_documentation
] ]
`yarn --silent jsdoc --readme plugins/chat/README.md -c #{config} #{files.join(" ")} -d #{destination}` `yarn --silent jsdoc --readme plugins/chat/README.md -c #{config} #{files.join(" ")} -d #{destination}`
# unecessary files # unnecessary files
%w[ %w[
documentation/chat/frontend/scripts/prism.min.js documentation/chat/frontend/scripts/prism.min.js
documentation/chat/frontend/scripts/prism.js documentation/chat/frontend/scripts/prism.js

View File

@ -168,13 +168,13 @@ task "plugin:install_gems", :plugin do |t, args|
puts "Done" puts "Done"
end end
def spec(plugin, parallel: false) def spec(plugin, parallel: false, argv: nil)
params = [] params = []
params << "--profile" if !parallel params << "--profile" if !parallel
params << "--fail-fast" if ENV["RSPEC_FAILFAST"] params << "--fail-fast" if ENV["RSPEC_FAILFAST"]
params << "--seed #{ENV["RSPEC_SEED"]}" if Integer(ENV["RSPEC_SEED"], exception: false) params << "--seed #{ENV["RSPEC_SEED"]}" if Integer(ENV["RSPEC_SEED"], exception: false)
params << argv if argv
ruby = `which ruby`.strip
# reject system specs as they are slow and need dedicated setup # reject system specs as they are slow and need dedicated setup
files = files =
Dir.glob("./plugins/#{plugin}/spec/**/*_spec.rb").reject { |f| f.include?("spec/system/") }.sort Dir.glob("./plugins/#{plugin}/spec/**/*_spec.rb").reject { |f| f.include?("spec/system/") }.sort
@ -187,15 +187,15 @@ def spec(plugin, parallel: false)
end end
desc "run plugin specs" desc "run plugin specs"
task "plugin:spec", :plugin do |t, args| task "plugin:spec", %i[plugin argv] do |_, args|
args.with_defaults(plugin: "*") args.with_defaults(plugin: "*")
spec(args[:plugin]) spec(args[:plugin], argv: args[:argv])
end end
desc "run plugin specs in parallel" desc "run plugin specs in parallel"
task "plugin:turbo_spec", :plugin do |t, args| task "plugin:turbo_spec", %i[plugin argv] do |_, args|
args.with_defaults(plugin: "*") args.with_defaults(plugin: "*")
spec(args[:plugin], parallel: true) spec(args[:plugin], parallel: true, argv: args[:argv])
end end
desc "run plugin qunit tests" desc "run plugin qunit tests"

View File

@ -15,6 +15,7 @@ require "parallel_tests/rspec/runner"
require "./lib/turbo_tests/reporter" require "./lib/turbo_tests/reporter"
require "./lib/turbo_tests/runner" require "./lib/turbo_tests/runner"
require "./lib/turbo_tests/json_rows_formatter" require "./lib/turbo_tests/json_rows_formatter"
require "./lib/turbo_tests/documentation_formatter"
module TurboTests module TurboTests
FakeException = Struct.new(:backtrace, :message, :cause) FakeException = Struct.new(:backtrace, :message, :cause)
@ -54,9 +55,18 @@ module TurboTests
end end
FakeExample = FakeExample =
Struct.new(:execution_result, :location, :full_description, :metadata, :location_rerun_argument) Struct.new(
:execution_result,
:location,
:description,
:full_description,
:metadata,
:location_rerun_argument,
:process_id,
)
class FakeExample class FakeExample
def self.from_obj(obj) def self.from_obj(obj, process_id)
obj = obj.symbolize_keys obj = obj.symbolize_keys
metadata = obj[:metadata].symbolize_keys metadata = obj[:metadata].symbolize_keys
@ -71,9 +81,11 @@ module TurboTests
new( new(
FakeExecutionResult.from_obj(obj[:execution_result]), FakeExecutionResult.from_obj(obj[:execution_result]),
obj[:location], obj[:location],
obj[:description],
obj[:full_description], obj[:full_description],
metadata, metadata,
obj[:location_rerun_argument], obj[:location_rerun_argument],
process_id,
) )
end end

View File

@ -0,0 +1,44 @@
# frozen_string_literal: true
RSpec::Support.require_rspec_core "formatters/base_text_formatter"
module TurboTests
# An RSpec formatter that prepends the process id to all messages
class DocumentationFormatter < ::RSpec::Core::Formatters::BaseTextFormatter
RSpec::Core::Formatters.register(self, :example_failed, :example_passed, :example_pending)
def example_passed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}",
:success,
)
output.flush
end
def example_pending(notification)
message = notification.example.execution_result.pending_message
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}" \
"(PENDING: #{message})",
:pending,
)
output.flush
end
def example_failed(notification)
output.puts RSpec::Core::Formatters::ConsoleCodes.wrap(
"[#{notification.example.process_id}] #{notification.example.full_description}" \
"(FAILED - #{next_failure_index})",
:failure,
)
output.flush
end
private
def next_failure_index
@next_failure_index ||= 0
@next_failure_index += 1
end
end
end

View File

@ -49,6 +49,7 @@ module TurboTests
{ {
execution_result: execution_result_to_json(example.execution_result), execution_result: execution_result_to_json(example.execution_result),
location: example.location, location: example.location,
description: example.description,
full_description: example.full_description, full_description: example.full_description,
metadata: { metadata: {
shared_group_inclusion_backtrace: shared_group_inclusion_backtrace:

View File

@ -35,6 +35,8 @@ module TurboTests
case name case name
when "p", "progress" when "p", "progress"
RSpec::Core::Formatters::ProgressFormatter RSpec::Core::Formatters::ProgressFormatter
when "d", "documentation"
TurboTests::DocumentationFormatter
else else
Kernel.const_get(name) Kernel.const_get(name)
end end

View File

@ -215,13 +215,13 @@ module TurboTests
message = @messages.pop message = @messages.pop
case message[:type] case message[:type]
when "example_passed" when "example_passed"
example = FakeExample.from_obj(message[:example]) example = FakeExample.from_obj(message[:example], message[:process_id])
@reporter.example_passed(example) @reporter.example_passed(example)
when "example_pending" when "example_pending"
example = FakeExample.from_obj(message[:example]) example = FakeExample.from_obj(message[:example], message[:process_id])
@reporter.example_pending(example) @reporter.example_pending(example)
when "example_failed" when "example_failed"
example = FakeExample.from_obj(message[:example]) example = FakeExample.from_obj(message[:example], message[:process_id])
@reporter.example_failed(example) @reporter.example_failed(example)
@failure_count += 1 @failure_count += 1
if fail_fast_met if fail_fast_met
@ -237,6 +237,7 @@ module TurboTests
@error = true @error = true
when "exit" when "exit"
exited += 1 exited += 1
@reporter.message("[#{message[:process_id]}] DONE (#{exited}/#{@num_processes + 1})")
break if exited == @num_processes + 1 break if exited == @num_processes + 1
else else
STDERR.puts("Unhandled message in main process: #{message}") STDERR.puts("Unhandled message in main process: #{message}")