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
autoload :Menu, 'qa/page/project/menu'
autoload :Members, 'qa/page/project/members'
module Artifact
autoload :Show, 'qa/page/project/artifact/show'
end
module Branches
autoload :Show, 'qa/page/project/branches/show'
end
......
......@@ -114,10 +114,6 @@ module QA
autoload :Show, 'qa/ee/page/project/show'
autoload :Menu, 'qa/ee/page/project/menu'
module Artifact
autoload :Show, 'qa/ee/page/project/artifact/show'
end
module SubMenus
autoload :SecurityCompliance, 'qa/ee/page/project/sub_menus/security_compliance'
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
show.click_browse_button
end
EE::Page::Project::Artifact::Show.perform do |show|
Page::Project::Artifact::Show.perform do |show|
show.go_to_directory(directory_name)
expect(show).to have_content(file_name)
end
......
......@@ -5,7 +5,7 @@ module QA
describe 'npm registry' do
include Runtime::Fixtures
let!(:registry_scope) { project.group.sandbox.path }
let!(:registry_scope) { Runtime::Namespace.sandbox_name }
let(:auth_token) do
unless Page::Main::Menu.perform(&:signed_in?)
Flow::Login.sign_in
......@@ -14,28 +14,87 @@ module QA
Resource::PersonalAccessToken.fabricate!.token
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
Resource::Project.fabricate_via_api! do |project|
project.name = 'npm-registry-project'
project.name = 'npm-project'
end
end
let(:package) do
Resource::Package.new.tap do |package|
package.name = "@#{registry_scope}/#{project.name}"
package.project = project
let!(:another_project) do
Resource::Project.fabricate_via_api! do |another_project|
another_project.name = 'npm-another-project'
another_project.template_name = 'express'
another_project.group = project.group
end
end
after do
package.remove_via_api!
let!(:runner) do
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
it 'publishes an npm package and then deletes it', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/944' 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 = {
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
let(:package_json) do
{
file_path: 'package.json',
content: <<~JSON
{
......@@ -47,19 +106,79 @@ module QA
}
}
JSON
}
npmrc = {
}
end
let(:npmrc) do
{
file_path: '.npmrc',
content: <<~NPMRC
//#{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/packages/npm/
@#{registry_scope}:registry=#{gitlab_address_with_port}/api/v4/projects/#{project.id}/packages/npm/
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
with_fixtures([npmrc, package_json]) do |dir|
Service::DockerRun::NodeJs.new(dir).publish!
Page::Project::Artifact::Show.perform do |artifacts|
artifacts.go_to_directory('node_modules')
artifacts.go_to_directory("@#{registry_scope}")
expect(artifacts).to have_content( "#{project.name}")
end
project.visit!
......
......@@ -49,7 +49,7 @@ module QA
@runner.remove_via_api!
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
Runtime::Logger.debug('Visiting the secondary Geo site')
......@@ -106,7 +106,7 @@ module QA
pipeline_job.click_browse_button
end
EE::Page::Project::Artifact::Show.perform do |artifact|
Page::Project::Artifact::Show.perform do |artifact|
artifact.go_to_directory(@directory_name)
expect(artifact).to have_content(@file_name)
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