Commit d50375e7 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'npm-ci-test' into 'master'

Add npm test for publish and install using CI/CD

See merge request gitlab-org/gitlab!59256
parents 24590d70 f0679fe1
...@@ -266,6 +266,10 @@ module QA ...@@ -266,6 +266,10 @@ module QA
autoload :Menu, 'qa/page/project/menu' autoload :Menu, 'qa/page/project/menu'
autoload :Members, 'qa/page/project/members' autoload :Members, 'qa/page/project/members'
module Artifact
autoload :Show, 'qa/page/project/artifact/show'
end
module Branches module Branches
autoload :Show, 'qa/page/project/branches/show' autoload :Show, 'qa/page/project/branches/show'
end end
......
...@@ -114,10 +114,6 @@ module QA ...@@ -114,10 +114,6 @@ module QA
autoload :Show, 'qa/ee/page/project/show' autoload :Show, 'qa/ee/page/project/show'
autoload :Menu, 'qa/ee/page/project/menu' autoload :Menu, 'qa/ee/page/project/menu'
module Artifact
autoload :Show, 'qa/ee/page/project/artifact/show'
end
module SubMenus module SubMenus
autoload :SecurityCompliance, 'qa/ee/page/project/sub_menus/security_compliance' autoload :SecurityCompliance, 'qa/ee/page/project/sub_menus/security_compliance'
autoload :Repository, 'qa/ee/page/project/sub_menus/repository' autoload :Repository, 'qa/ee/page/project/sub_menus/repository'
......
# frozen_string_literal: true
module QA
module EE
module Page
module Project
module Artifact
class Show < QA::Page::Base
view 'app/views/projects/artifacts/_tree_directory.html.haml' do
element :directory_name_link
end
def go_to_directory(name)
click_element(:directory_name_link, directory_name: name)
end
end
end
end
end
end
end
# frozen_string_literal: true
module QA
module Page
module Project
module Artifact
class Show < QA::Page::Base
view 'app/views/projects/artifacts/_tree_directory.html.haml' do
element :directory_name_link
end
def go_to_directory(name)
click_element(:directory_name_link, directory_name: name)
end
end
end
end
end
end
...@@ -67,7 +67,7 @@ module QA ...@@ -67,7 +67,7 @@ module QA
show.click_browse_button show.click_browse_button
end end
EE::Page::Project::Artifact::Show.perform do |show| Page::Project::Artifact::Show.perform do |show|
show.go_to_directory(directory_name) show.go_to_directory(directory_name)
expect(show).to have_content(file_name) expect(show).to have_content(file_name)
end end
......
...@@ -5,7 +5,7 @@ module QA ...@@ -5,7 +5,7 @@ module QA
describe 'npm registry' do describe 'npm registry' do
include Runtime::Fixtures include Runtime::Fixtures
let!(:registry_scope) { project.group.sandbox.path } let!(:registry_scope) { Runtime::Namespace.sandbox_name }
let(:auth_token) do let(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?) unless Page::Main::Menu.perform(&:signed_in?)
Flow::Login.sign_in Flow::Login.sign_in
...@@ -14,28 +14,87 @@ module QA ...@@ -14,28 +14,87 @@ module QA
Resource::PersonalAccessToken.fabricate!.token Resource::PersonalAccessToken.fabricate!.token
end end
let(:uri) { URI.parse(Runtime::Scenario.gitlab_address) }
let(:gitlab_address_with_port) { "#{uri.scheme}://#{uri.host}:#{uri.port}" }
let(:gitlab_host_with_port) { "#{uri.host}:#{uri.port}" }
let!(:project) do let!(:project) do
Resource::Project.fabricate_via_api! do |project| Resource::Project.fabricate_via_api! do |project|
project.name = 'npm-registry-project' project.name = 'npm-project'
end end
end end
let(:package) do let!(:another_project) do
Resource::Package.new.tap do |package| Resource::Project.fabricate_via_api! do |another_project|
package.name = "@#{registry_scope}/#{project.name}" another_project.name = 'npm-another-project'
package.project = project another_project.template_name = 'express'
another_project.group = project.group
end end
end end
after do let!(:runner) do
package.remove_via_api! Resource::Runner.fabricate! do |runner|
runner.name = "qa-runner-#{Time.now.to_i}"
runner.tags = ["runner-for-#{project.group.name}"]
runner.executor = :docker
runner.token = project.group.sandbox.runners_token
end
end
let(:gitlab_ci_deploy_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: node:14-buster
stages:
- deploy
deploy:
stage: deploy
script:
- npm publish
only:
- "#{project.default_branch}"
tags:
- "runner-for-#{project.group.name}"
YAML
}
end
let(:gitlab_ci_install_yaml) do
{
file_path: '.gitlab-ci.yml',
content:
<<~YAML
image: node:latest
stages:
- install
install:
stage: install
script:
- "npm config set @#{registry_scope}:registry #{gitlab_address_with_port}/api/v4/packages/npm/"
- "npm install #{package.name}"
cache:
key: ${CI_BUILD_REF_NAME}
paths:
- node_modules/
artifacts:
paths:
- node_modules/
only:
- "#{another_project.default_branch}"
tags:
- "runner-for-#{another_project.group.name}"
YAML
}
end end
it 'publishes an npm package and then deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/944' do let(:package_json) do
uri = URI.parse(Runtime::Scenario.gitlab_address) {
gitlab_host_with_port = "#{uri.host}:#{uri.port}"
gitlab_address_with_port = "#{uri.scheme}://#{uri.host}:#{uri.port}"
package_json = {
file_path: 'package.json', file_path: 'package.json',
content: <<~JSON content: <<~JSON
{ {
...@@ -48,18 +107,78 @@ module QA ...@@ -48,18 +107,78 @@ module QA
} }
JSON JSON
} }
npmrc = { end
let(:npmrc) do
{
file_path: '.npmrc', file_path: '.npmrc',
content: <<~NPMRC content: <<~NPMRC
//#{gitlab_host_with_port}/api/v4/projects/#{project.id}/packages/npm/:_authToken=#{auth_token} //#{gitlab_host_with_port}/api/v4/projects/#{project.id}/packages/npm/:_authToken=#{auth_token}
//#{gitlab_host_with_port}/api/v4/packages/npm/:_authToken=#{auth_token} @#{registry_scope}:registry=#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/npm/
@#{registry_scope}:registry=#{gitlab_address_with_port}/api/v4/packages/npm/
NPMRC NPMRC
} }
end
let(:package) do
Resource::Package.new.tap do |package|
package.name = "@#{registry_scope}/#{project.name}"
package.project = project
end
end
after do
package.remove_via_api!
runner.remove_via_api!
project.remove_via_api!
another_project.remove_via_api!
end
it 'push and pull a npm package via CI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/1772' do
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_deploy_yaml,
npmrc,
package_json
])
end
project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('deploy')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
end
Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = another_project
commit.commit_message = 'Add .gitlab-ci.yml'
commit.add_files([
gitlab_ci_install_yaml
])
end
another_project.visit!
Flow::Pipeline.visit_latest_pipeline
Page::Project::Pipeline::Show.perform do |pipeline|
pipeline.click_job('install')
end
Page::Project::Job::Show.perform do |job|
expect(job).to be_successful(timeout: 800)
job.click_browse_button
end
# Use a node docker container to publish the package Page::Project::Artifact::Show.perform do |artifacts|
with_fixtures([npmrc, package_json]) do |dir| artifacts.go_to_directory('node_modules')
Service::DockerRun::NodeJs.new(dir).publish! artifacts.go_to_directory("@#{registry_scope}")
expect(artifacts).to have_content( "#{project.name}")
end end
project.visit! project.visit!
......
...@@ -49,7 +49,7 @@ module QA ...@@ -49,7 +49,7 @@ module QA
@runner.remove_via_api! @runner.remove_via_api!
end end
# Test code is based on qa/specs/features/ee/browser_ui/4_verify/locked_artifacts_spec.rb # Test code is based on qa/specs/features/browser_ui/4_verify/locked_artifacts_spec.rb
it 'replicates the job log to the secondary Geo site', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/908' do it 'replicates the job log to the secondary Geo site', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/908' do
Runtime::Logger.debug('Visiting the secondary Geo site') Runtime::Logger.debug('Visiting the secondary Geo site')
...@@ -106,7 +106,7 @@ module QA ...@@ -106,7 +106,7 @@ module QA
pipeline_job.click_browse_button pipeline_job.click_browse_button
end end
EE::Page::Project::Artifact::Show.perform do |artifact| Page::Project::Artifact::Show.perform do |artifact|
artifact.go_to_directory(@directory_name) artifact.go_to_directory(@directory_name)
expect(artifact).to have_content(@file_name) expect(artifact).to have_content(@file_name)
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment