sasjs-tests is a test suite for the SASjs adapter.
Browser-based integration testing for @sasjs/adapter using TypeScript, Custom Elements, and zero dependencies.
When developing on @sasjs/adapter, it's good practice to run the test suite against your changed version of the adapter to ensure that existing functionality has not been impacted.
You can use the provided update:adapter NPM script for this.
npm run update:adapterThis scripts builds a new version of the adapter and installs it in the sasjs-tests project.
There are three prerequisites to be able to run the tests:
- Correct server configuration for the SASjs adapter.
sasjs-testsdeployed to your SAS server.- The required SAS services created on the same server.
There is a config.json file in the /public folder which specifies the configuration for the SASjs adapter. You can set the values within the sasjsConfig property in this file to match your SAS server configuration.
Tests are defined in src/testSuites/:
- Basic.ts - Login, config, session management, debug mode
- RequestData.ts - Data serialization (sendArr, sendObj) with various types
- FileUpload.ts - File upload functionality (VIYA only)
- Compute.ts - Compute API, JES API, executeScript (VIYA only)
- SasjsRequests.ts - WORK tables, log capture
- SpecialCases.ts - Edge cases (currently disabled)
Each test suite follows this pattern:
export const myTests = (adapter: SASjs): TestSuite => ({
name: 'My Test Suite',
tests: [
{
title: 'Should do something',
description: 'Description of what this tests',
test: async () => {
// Test logic - return a value
return adapter.request('service', data)
},
assertion: (response) => {
// Assertion - return true/false
return response.success === true
}
}
],
beforeAll: async () => {
// Optional: runs once before all tests
},
afterAll: async () => {
// Optional: runs once after all tests
}
})Cypress accesses Shadow DOM using a custom command:
cy.get('login-form').shadow().find('input#username').type('user')The shadow() command is defined in cypress/support/commands.js.
npm run buildThis creates a dist/ folder ready for deployment.
There is a deploy NPM script provided in the sasjs-tests project's package.json.
It updates sasjs-tests to use the latest version of the adapter, and deploys to a specified server via SSH using the rsync command.
To be able to run the deploy script, two environment variables need to be set:
SSH_ACCOUNT- your SSH account, this is of the form [email protected]DEPLOY_PATH- the path on the server wheresasjs-testswill be deployed to, typically/var/www/html/<some-subfolder>.
So you can run the script like so:
[email protected] DEPLOY_PATH=/var/www/html/my-folder/sasjs-tests npm run deployIf you are on WINDOWS, you will first need to install one dependency:
npm i -g copyfilesand then run to build:
npm run update:adapter && npm run buildwhen it finishes run to deploy:
scp -rp ./build/* [email protected]:/var/www/html/my-folder/sasjs-testsIf you'd like to deploy just sasjs-tests without changing the adapter version, you can use the deploy:tests script, while also setting the same environment variables as above.
The below services need to be created on your SAS server, at the location specified as the appLoc in the SASjs configuration.
The code below will work on ALL SAS platforms (Viya, SAS 9 EBI, SASjs Server).
filename mc url "https://raw.githubusercontent.com/sasjs/core/main/all.sas";
%inc mc;
%let apploc=/Public/app/adapter-tests;
filename ft15f001 temp lrecl=1000;
parmcards4;
%webout(FETCH)
%webout(OPEN)
%macro x();
%if %symexist(sasjs_tables) %then %do i=1 %to %sysfunc(countw(&sasjs_tables));
%let table=%scan(&sasjs_tables,&i);
%webout(OBJ,&table,missing=STRING,showmeta=YES)
%end;
%else %do i=1 %to &_webin_file_count;
%webout(OBJ,&&_webin_name&i,missing=STRING,showmeta=YES)
%end;
%mend; %x()
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&apploc/services/common,name=sendObj)
parmcards4;
%webout(FETCH)
%webout(OPEN)
%macro x();
%if %symexist(sasjs_tables) %then %do i=1 %to %sysfunc(countw(&sasjs_tables));
%let table=%scan(&sasjs_tables,&i);
%webout(ARR,&table,missing=STRING,showmeta=YES)
%end;
%else %do i=1 %to &_webin_file_count;
%webout(ARR,&&_webin_name&i,missing=STRING,showmeta=YES)
%end;
%mend; %x()
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&apploc/services/common,name=sendArr)
parmcards4;
data work.macvars;
set sashelp.vmacro;
run;
%webout(OPEN)
%webout(OBJ,macvars)
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&apploc/services/common,name=sendMacVars)
parmcards4;
If you can keep your head when all about you
Are losing theirs and blaming it on you,
If you can trust yourself when all men doubt you,
But make allowance for their doubting too;
;;;;
%mx_createwebservice(path=&apploc/services/common,name=makeErr)
parmcards4;
%webout(OPEN)
data _null_;
file _webout;
put ' the discovery channel ';
run;
%webout(CLOSE)
;;;;
%mx_createwebservice(path=&apploc/services/common,name=invalidJSON)You should now be able to access the tests in your browser at the deployed path on your server.
sasjs deploy -t <target>The sasjs-cypress-run.sh script sends Matrix chat notifications on test failure:
./sasjs-cypress-run.sh $MATRIX_ACCESS_TOKEN $PR_NUMBERNotification format:
Automated sasjs-tests failed on the @sasjs/adapter PR: <PR_NUMBER>
The tests require SAS services to be deployed at the appLoc specified in config.json.
Services expected:
common/sendArr- Echo back array datacommon/sendObj- Echo back object data- (Additional services per test suite)
Deploy these services using SASjs CLI or manually.
<login-form>- SAS authentication<tests-view>- Test orchestrator with run controls<test-suite>- Test suite display with stats<test-card>- Individual test with status (pending/running/passed/failed)
All components use Shadow DOM for style encapsulation and expose custom events for interactivity.
- Create file in
src/testSuites/MyNewTests.ts - Export function returning TestSuite
- Import in
src/index.ts - Add to
testSuitesarray inshowTests()function
Components are in src/components/:
- Edit
.tsfile - Styles are in corresponding
.cssfile - Rebuild with
npm run build