diff --git a/test/README.md b/test/README.md index dd3a051db..b67f76bec 100644 --- a/test/README.md +++ b/test/README.md @@ -61,5 +61,5 @@ you’ll want to consult the documentation of the following libraries we use: (`browser`, `$`, `waitForVisible`, …) * [Mocha](https://mochajs.org/) as the general testing framework (`describe`, `it`, `before`, …) -* [`assert`](https://nodejs.org/api/assert.html) for simple assertions - (`ok`, `strictEqual`, …) +* [`expect`](https://webdriver.io/docs/api/expect-webdriverio/) for assertions + (`toBe`, `toEqual`, …) diff --git a/test/helpers/default-functions.ts b/test/helpers/default-functions.ts index 943aa8617..716406e75 100644 --- a/test/helpers/default-functions.ts +++ b/test/helpers/default-functions.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import axios, { AxiosResponse } from 'axios'; import lodash from 'lodash'; import { Context } from 'mocha'; @@ -176,7 +175,7 @@ export function defaultFunctions(): void { const changes = result.data.query.recentchanges; const foundResult = lodash.find( changes, expectedChange ); - assert.strictEqual( result.status, 200 ); + expect( result.status ).toBe( 200 ); if ( !foundResult ) { testEnv.testLog.error( 'Could not find:' ); diff --git a/test/specs/confirm_edit/confirm-edit.ts b/test/specs/confirm_edit/confirm-edit.ts index 5973a8df8..64af96912 100644 --- a/test/specs/confirm_edit/confirm-edit.ts +++ b/test/specs/confirm_edit/confirm-edit.ts @@ -1,5 +1,3 @@ -import assert from 'assert'; - describe( 'ConfirmEdit', function () { it( 'Should allow to edit with captcha', async function () { const executionResult = await browser.editPage( @@ -9,6 +7,6 @@ describe( 'ConfirmEdit', function () { 'paris' ); - assert.strictEqual( executionResult, 'something great' ); + expect( executionResult ).toBe( 'something great' ); } ); } ); diff --git a/test/specs/fedprops/item.ts b/test/specs/fedprops/item.ts index 0a94d5616..c062f9253 100644 --- a/test/specs/fedprops/item.ts +++ b/test/specs/fedprops/item.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { AxiosError } from 'axios'; import { getTestString } from 'wdio-mediawiki/Util.js'; import SpecialEntityPage from 'wdio-wikibase/pageobjects/item.page.js'; @@ -17,11 +16,9 @@ describe( 'Fed props Item', function () { const result = await browser.makeRequest( `${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbsearchentities&search=ISNI&format=json&language=en&type=property` ); - const success = result.data.success; - const searchResults = result.data.search; - assert.strictEqual( success, 1 ); - assert( searchResults.length > 0 ); + expect( result.data.success ).toBe( 1 ); + expect( result.data.search.length ).toBeGreaterThan( 0 ); } ); it( 'can add a federated property and it shows up in the ui', async function () { @@ -42,10 +39,9 @@ describe( 'Fed props Item', function () { await ItemPage.open( itemId ); - const actualPropertyValue = await $( - '.wikibase-statementgroupview-property' - ).getText(); - assert( actualPropertyValue.includes( propertyValue ) ); // value is the label + await expect( + $( '.wikibase-statementgroupview-property' ) + ).toHaveTextContaining( propertyValue ); // value is the label await SpecialEntityPage.addStatementLink; } ); @@ -54,25 +50,24 @@ describe( 'Fed props Item', function () { try { await SpecialEntityDataPage.getData( 'Q1', 'ttl' ); } catch ( error ) { - assert( error instanceof AxiosError ); - assert.equal( error.request.res.statusCode, 500 ); + expect( error ).toBeInstanceOf( AxiosError ); + expect( error.request.res.statusCode ).toBe( 500 ); } } ); it( 'should show up in Special:EntityData with json', async function () { const data = await SpecialEntityDataPage.getData( 'Q1' ); - assert.notEqual( - data.entities.Q1.claims[ 'http://www.wikidata.org/entity/P213' ], - null - ); + expect( + data.entities.Q1.claims[ 'http://www.wikidata.org/entity/P213' ] + ).not.toBeNull(); } ); it( 'should NOT show up in Special:EntityData with rdf', async function () { try { await SpecialEntityDataPage.getData( 'Q1', 'rdf' ); } catch ( error ) { - assert( error instanceof AxiosError ); - assert.equal( error.request.res.statusCode, 500 ); + expect( error ).toBeInstanceOf( AxiosError ); + expect( error.request.res.statusCode ).toBe( 500 ); } } ); @@ -90,12 +85,12 @@ describe( 'Fed props Item', function () { await QueryServiceUIPage.resultTable; // Item should never have made its way into the query service, as TTL doesnt work - assert( - !( await QueryServiceUIPage.resultIncludes( + await expect( + QueryServiceUIPage.resultIncludes( `<${ testEnv.vars.WIKIBASE_URL }/entity/${ itemId }>`, propertyValue - ) ) - ); + ) + ).resolves.toBe( false ); } ); it( 'should NOT show up in queryservice ui after creation', async function () { @@ -106,23 +101,33 @@ describe( 'Fed props Item', function () { await QueryServiceUIPage.resultTable; // Item should never have made its way into the query service, as TTL doesnt work - assert( !( await QueryServiceUIPage.resultIncludes( 'schema:version' ) ) ); - assert( !( await QueryServiceUIPage.resultIncludes( 'schema:dateModified' ) ) ); - assert( !( await QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' ) ) ); - - assert( !( await QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel ) ) ); - - assert( - !( await QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' ) ) + await expect( + QueryServiceUIPage.resultIncludes( 'schema:version' ) + ).resolves.toBe( false ); + await expect( + QueryServiceUIPage.resultIncludes( 'schema:dateModified' ) + ).resolves.toBe( false ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' ) + ).resolves.toBe( false ); + + await expect( + QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel ) + ).resolves.toBe( false ); + + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' ) + ).resolves.toBe( false ); + + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' ) + ).resolves.toBe( false ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '1' ) + ).resolves.toBe( false ); + + await expect( QueryServiceUIPage.resultIncludes( 'p:P213' ) ).resolves.toBe( + false ); - - assert( - !( await QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' ) ) - ); - assert( - !( await QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '1' ) ) - ); - - assert( !( await QueryServiceUIPage.resultIncludes( 'p:P213' ) ) ); } ); } ); diff --git a/test/specs/fedprops/prefetching.ts b/test/specs/fedprops/prefetching.ts index 429c7342b..0ce4f1eea 100644 --- a/test/specs/fedprops/prefetching.ts +++ b/test/specs/fedprops/prefetching.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ItemPage from '../../helpers/pages/entity/item.page.js'; @@ -34,7 +33,7 @@ describe( 'Property Prefetching', function () { }; } ) ); - assert.strictEqual( claims.length, NUM_PROPERTIES ); + expect( claims ).toHaveLength( NUM_PROPERTIES ); const data = { claims: claims }; itemId = await WikibaseApi.createItem( getTestString( itemLabel ), data ); @@ -51,11 +50,11 @@ describe( 'Property Prefetching', function () { statements.map( async ( statement ) => statement.getAttribute( 'id' ) ) ); - assert.strictEqual( propertyGuids.length, NUM_PROPERTIES ); + expect( propertyGuids ).toHaveLength( NUM_PROPERTIES ); for ( const guid of propertyGuids ) { const response = await browser.deleteClaim( guid ); - assert.strictEqual( response.success, 1 ); + expect( response.success ).toBe( 1 ); } // Sleep for 2 seconds to ensure post edit things run @@ -68,8 +67,7 @@ describe( 'Property Prefetching', function () { await $( '#pagehistory' ); // +1 for the initial item creation - assert.strictEqual( - ( await $$( '#pagehistory li' ) ).length, + await expect( $$( '#pagehistory li' ) ).resolves.toHaveLength( NUM_PROPERTIES + 1 ); } ); @@ -83,6 +81,6 @@ describe( 'Property Prefetching', function () { // +1 for the initial item creation // +1 for the Main Page creation? // +1 for ? - assert.strictEqual( ( await $$( 'ul.special li' ) ).length, NUM_PROPERTIES + 3 ); + await expect( $$( 'ul.special li' ) ).resolves.toHaveLength( NUM_PROPERTIES + 3 ); } ); } ); diff --git a/test/specs/pingback/pingback.ts b/test/specs/pingback/pingback.ts index 934552137..4fafe1a7d 100644 --- a/test/specs/pingback/pingback.ts +++ b/test/specs/pingback/pingback.ts @@ -1,5 +1,3 @@ -import assert from 'assert'; - describe( 'Pingback', function () { it( 'Should ping on first page request', async function () { await browser.url( testEnv.vars.WIKIBASE_URL + '/wiki/Main_Page' ); @@ -10,16 +8,16 @@ describe( 'Pingback', function () { const sqlResult = await browser.dbQuery( 'SELECT * from updatelog where ul_key LIKE "WikibasePingback%"' ); - assert.strictEqual( sqlResult.includes( 'WikibasePingback\t' ), true ); - assert.strictEqual( sqlResult.includes( 'WikibasePingback-1.' ), true ); + expect( sqlResult.includes( 'WikibasePingback\t' ) ).toBe( true ); + expect( sqlResult.includes( 'WikibasePingback-1.' ) ).toBe( true ); const result = await browser.makeRequest( 'http://mediawiki.svc' ); - assert.strictEqual( result.data.length, 2 ); + expect( result.data ).toHaveLength( 2 ); const requestData = JSON.parse( Object.keys( result.data[ 0 ] )[ 0 ].replace( ';', '' ) ); - assert.strictEqual( requestData.schema, 'WikibasePingback' ); + expect( requestData.schema ).toBe( 'WikibasePingback' ); } ); } ); diff --git a/test/specs/quickstatements/quickstatements.ts b/test/specs/quickstatements/quickstatements.ts index 9ea4f34fd..1e4edd1c7 100644 --- a/test/specs/quickstatements/quickstatements.ts +++ b/test/specs/quickstatements/quickstatements.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { AxiosResponse } from 'axios'; import lodash from 'lodash'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; @@ -107,8 +106,8 @@ describe( 'QuickStatements Service', function () { const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); const responseQ2Data = await SpecialEntityDataPage.getData( 'Q2' ); - assert.strictEqual( responseQ1Data.entities.Q1.id, 'Q1' ); - assert.strictEqual( responseQ2Data.entities.Q2.id, 'Q2' ); + expect( responseQ1Data.entities.Q1.id ).toBe( 'Q1' ); + expect( responseQ2Data.entities.Q2.id ).toBe( 'Q2' ); } ); it( 'Should be able to create item with label', async function () { @@ -117,11 +116,7 @@ describe( 'QuickStatements Service', function () { await browser.executeQuickStatement( 'CREATE\nLAST|Len|"Best label"' ); const responseQ3Data = await SpecialEntityDataPage.getData( 'Q3' ); - - assert.strictEqual( - responseQ3Data.entities.Q3.labels.en.value, - 'Best label' - ); + expect( responseQ3Data.entities.Q3.labels.en.value ).toBe( 'Best label' ); } ); it( 'Should be able to create an item with statement', async function () { @@ -145,8 +140,7 @@ describe( 'QuickStatements Service', function () { // go look at wikibase const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - - assert( lodash.isEmpty( responseQ1Data.entities.Q1.aliases ) !== true ); + expect( lodash.isEmpty( responseQ1Data.entities.Q1.aliases ) ).toBe( false ); } ); it( 'Should be able to add a label to an item', async function () { @@ -154,8 +148,7 @@ describe( 'QuickStatements Service', function () { // go look at wikibase const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - - assert( lodash.isEmpty( responseQ1Data.entities.Q1.labels ) !== true ); + expect( lodash.isEmpty( responseQ1Data.entities.Q1.labels ) ).toBe( false ); } ); it( 'Should be able to add a description to an item', async function () { @@ -163,8 +156,7 @@ describe( 'QuickStatements Service', function () { // go look at wikibase const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - - assert( lodash.isEmpty( responseQ1Data.entities.Q1.descriptions ) !== true ); + expect( lodash.isEmpty( responseQ1Data.entities.Q1.descriptions ) ).toBe( false ); } ); it.skip( 'Should be able to add a sitelink to an item', async function () { @@ -172,8 +164,7 @@ describe( 'QuickStatements Service', function () { // go look at wikibase const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - - assert( lodash.isEmpty( responseQ1Data.entities.Q1.sitelinks ) !== true ); + expect( lodash.isEmpty( responseQ1Data.entities.Q1.sitelinks ) ).toBe( false ); } ); it( 'Should be able to add a statement to an item', async function () { @@ -182,14 +173,12 @@ describe( 'QuickStatements Service', function () { await browser.executeQuickStatement( `Q1|${ propertyId }|"Will it blend?"` ); const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - assert.strictEqual( - responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].type, + expect( responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].type ).toBe( 'statement' ); - assert.strictEqual( - responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].mainsnak.datavalue.value, - 'Will it blend?' - ); + expect( + responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].mainsnak.datavalue.value + ).toBe( 'Will it blend?' ); } ); describe( 'Should be able to add qualifiers to statements with a range of datatypes', function () { @@ -212,10 +201,9 @@ describe( 'QuickStatements Service', function () { const responseQ1 = await browser.makeRequest( `${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbgetclaims&format=json&entity=${ itemId }` ); - assert.strictEqual( - getQualifierType( responseQ1, mainPropertyId, qualifierPropertyId ), - qualifierSnakDataType - ); + expect( + getQualifierType( responseQ1, mainPropertyId, qualifierPropertyId ) + ).toBe( qualifierSnakDataType ); } ); } ); } ); @@ -229,8 +217,7 @@ describe( 'QuickStatements Service', function () { ); const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - assert.strictEqual( - responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].type, + expect( responseQ1Data.entities.Q1.claims[ propertyId ][ 0 ].type ).toBe( 'statement' ); } ); @@ -253,8 +240,10 @@ describe( 'QuickStatements Service', function () { propertyIdItem ); - assert( typeof refValue !== 'string' ); - assert.strictEqual( refValue.id, 'Q2' ); + expect( typeof refValue ).not.toBe( 'string' ); + if ( typeof refValue !== 'string' ) { + expect( refValue.id ).toBe( 'Q2' ); + } } ); it( 'Should be able to add a property with "url" reference', async function () { @@ -270,9 +259,9 @@ describe( 'QuickStatements Service', function () { const response = await browser.makeRequest( `${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbgetclaims&format=json&entity=${ itemId }` ); - const refValue = getReferenceValue( response, propertyIdItem, propertyURL ); - - assert.strictEqual( refValue, 'https://www.wikidata.org' ); + expect( getReferenceValue( response, propertyIdItem, propertyURL ) ).toBe( + 'https://www.wikidata.org' + ); } ); it( 'Should be able to add a property with "string" reference', async function () { @@ -286,9 +275,9 @@ describe( 'QuickStatements Service', function () { const response = await browser.makeRequest( `${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbgetclaims&format=json&entity=${ itemId }` ); - const refValue = getReferenceValue( response, propertyIdItem, propertyId ); - - assert.strictEqual( refValue, 'some string' ); + expect( getReferenceValue( response, propertyIdItem, propertyId ) ).toBe( + 'some string' + ); } ); it( 'Should be able to add and remove a property on an item', async function () { @@ -297,28 +286,19 @@ describe( 'QuickStatements Service', function () { await browser.executeQuickStatement( `${ itemId }|${ propertyIdItem }|Q1` ); let responseData = await SpecialEntityDataPage.getData( itemId ); - assert.strictEqual( - propertyIdItem in responseData.entities[ itemId ].claims, - true - ); + expect( propertyIdItem in responseData.entities[ itemId ].claims ).toBe( true ); await browser.executeQuickStatement( `-${ itemId }|${ propertyIdItem }|Q1` ); responseData = await SpecialEntityDataPage.getData( itemId ); - assert.strictEqual( - propertyIdItem in responseData.entities[ itemId ].claims, - false - ); + expect( propertyIdItem in responseData.entities[ itemId ].claims ).toBe( false ); } ); it( 'Should be able to change label', async function () { await browser.executeQuickStatement( 'Q1|LSv|"Some other label"' ); const responseQ1Data = await SpecialEntityDataPage.getData( 'Q1' ); - assert.strictEqual( - responseQ1Data.entities.Q1.labels.sv.value, - 'Some other label' - ); + expect( responseQ1Data.entities.Q1.labels.sv.value ).toBe( 'Some other label' ); } ); it( 'Should be able to merge two items', async function () { @@ -327,7 +307,7 @@ describe( 'QuickStatements Service', function () { await browser.executeQuickStatement( 'MERGE|Q1|Q2' ); const responseQ2Data = await SpecialEntityDataPage.getData( 'Q2' ); - assert.strictEqual( responseQ2Data.entities.Q1.id, 'Q1' ); + expect( responseQ2Data.entities.Q1.id ).toBe( 'Q1' ); } ); it( 'Should have a Last Batches button', async function () { diff --git a/test/specs/repo/api.ts b/test/specs/repo/api.ts index 6ab508a96..6290be1eb 100644 --- a/test/specs/repo/api.ts +++ b/test/specs/repo/api.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { wikibasePropertyString } from '../../helpers/wikibase-property-types.js'; @@ -33,8 +32,8 @@ describe( 'Wikibase API', function () { data ); - assert.strictEqual( itemId.startsWith( 'Q' ), true ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( itemId.startsWith( 'Q' ) ).toBe( true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); } ); } ); } ); diff --git a/test/specs/repo/extensions/babel.ts b/test/specs/repo/extensions/babel.ts index 44bd9b7e4..131344e0c 100644 --- a/test/specs/repo/extensions/babel.ts +++ b/test/specs/repo/extensions/babel.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; describe( 'Babel', function () { @@ -18,17 +17,13 @@ describe( 'Babel', function () { '{{#babel: sv | en }}' ); - assert.strictEqual( - executionContent.includes( - 'Den här användaren har svenska som modersmål.' - ), - true - ); - assert.strictEqual( + expect( + executionContent.includes( 'Den här användaren har svenska som modersmål.' ) + ).toBe( true ); + expect( executionContent.includes( 'This user has a native understanding of English.' - ), - true - ); + ) + ).toBe( true ); } ); } ); diff --git a/test/specs/repo/extensions/entityschema.ts b/test/specs/repo/extensions/entityschema.ts index 7be421fb0..1e9461423 100644 --- a/test/specs/repo/extensions/entityschema.ts +++ b/test/specs/repo/extensions/entityschema.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { readFile } from 'fs/promises'; import { utf8 } from '../../../helpers/readFileEncoding.js'; @@ -32,28 +31,16 @@ describe( 'EntitySchema', function () { await $( '#entityschema-schema-text' ); - const entitySchemaEl = await $( '#entityschema-schema-text' ); - const actualTemplate = ( await entitySchemaEl.getText() ).trim(); - const actualTemplateHtml = ( await entitySchemaEl.getHTML() ).trim(); - const actualLabel = ( await $( '.entityschema-title-label' ).getText() ).trim(); - const actualId = ( await $( '.entityschema-title-id' ).getText() ).trim(); - const actualDescription = ( - await $( '.entityschema-description' ).getText() - ).trim(); - - assert.strictEqual( actualDescription, testDescription ); - assert.strictEqual( actualTemplate, shexTemplate ); - assert.strictEqual( actualLabel, testLabel ); - assert.strictEqual( actualId, '(E1)' ); - assert.ok( - actualTemplateHtml.includes( 'mw-highlight' ), - 'Should contain mw-highlight class in HTML' - ); + const entitySchemaEl = $( '#entityschema-schema-text' ); + await expect( $( '.entityschema-description' ) ).toHaveText( testDescription ); + await expect( entitySchemaEl ).toHaveText( shexTemplate ); + await expect( $( '.entityschema-title-label' ) ).toHaveText( testLabel ); + await expect( $( '.entityschema-title-id' ) ).toHaveText( '(E1)' ); + await expect( entitySchemaEl.$( 'div' ) ).toHaveElementClass( 'mw-highlight' ); - const linkUrl = await $( '.external.entityschema-check-schema' ).getAttribute( - 'href' + await expect( $( '.external.entityschema-check-schema' ) ).toHaveAttrContaining( + 'href', + 'http://validator.svc' ); - - assert( linkUrl.includes( 'http://validator.svc' ) ); } ); } ); diff --git a/test/specs/repo/extensions/nuke.ts b/test/specs/repo/extensions/nuke.ts index b9ebbb831..9abf58698 100644 --- a/test/specs/repo/extensions/nuke.ts +++ b/test/specs/repo/extensions/nuke.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; describe( 'Nuke', function () { @@ -20,7 +19,7 @@ describe( 'Nuke', function () { {} ); - assert.strictEqual( pageExistsResult.status, 200 ); + expect( pageExistsResult.status ).toBe( 200 ); await LoginPage.login( testEnv.vars.MW_ADMIN_NAME, @@ -48,6 +47,6 @@ describe( 'Nuke', function () { {} ); - assert.strictEqual( pageIsGoneResult.status, 404 ); + expect( pageIsGoneResult.status ).toBe( 404 ); } ); } ); diff --git a/test/specs/repo/extensions/scribunto.ts b/test/specs/repo/extensions/scribunto.ts index 257278e4e..467e8e93e 100644 --- a/test/specs/repo/extensions/scribunto.ts +++ b/test/specs/repo/extensions/scribunto.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { readFile } from 'fs/promises'; import { utf8 } from '../../../helpers/readFileEncoding.js'; @@ -26,7 +25,7 @@ describe( 'Scribunto', function () { ); // should come from executed lua script - assert( executionContent.includes( 'Hello, world!' ) ); + expect( executionContent.includes( 'Hello, world!' ) ).toBe( true ); } ); it( 'Should be able to execute lua module within 0.05 seconds', async function () { @@ -35,7 +34,7 @@ describe( 'Scribunto', function () { 'LuaTest' ); - assert( cpuTime.value < 0.05 ); - assert.strictEqual( cpuTime.scale, 'seconds' ); + expect( cpuTime.value ).toBeLessThan( 0.05 ); + expect( cpuTime.scale ).toBe( 'seconds' ); } ); } ); diff --git a/test/specs/repo/extensions/universal-language-selector.ts b/test/specs/repo/extensions/universal-language-selector.ts index 2ac0deff4..cc9530325 100644 --- a/test/specs/repo/extensions/universal-language-selector.ts +++ b/test/specs/repo/extensions/universal-language-selector.ts @@ -1,5 +1,3 @@ -import assert from 'assert'; - describe( 'UniversalLanguageSelector', function () { beforeEach( async function () { await browser.skipIfExtensionNotPresent( this, 'UniversalLanguageSelector' ); @@ -10,8 +8,6 @@ describe( 'UniversalLanguageSelector', function () { await $( '#searchInput' ).click(); await $( '.imeselector' ).click(); - const firstLang = await $( '.imeselector-menu h3' ).getText(); - - assert.strictEqual( firstLang, 'English' ); + await expect( $( '.imeselector-menu h3' ) ).toHaveText( 'English' ); } ); } ); diff --git a/test/specs/repo/extensions/visual-editor.ts b/test/specs/repo/extensions/visual-editor.ts index 19d898f74..d3155235b 100644 --- a/test/specs/repo/extensions/visual-editor.ts +++ b/test/specs/repo/extensions/visual-editor.ts @@ -1,5 +1,3 @@ -import assert from 'assert'; - describe( 'VisualEditor', function () { beforeEach( async function () { await browser.skipIfExtensionNotPresent( this, 'VisualEditor' ); @@ -33,8 +31,6 @@ describe( 'VisualEditor', function () { await $( '.oo-ui-processDialog-actions-primary a' ).click(); - const contentBody = await $( '.mw-parser-output' ).getText(); - - assert.strictEqual( contentBody, 'TEST' ); + await expect( $( '.mw-parser-output' ) ).toHaveText( 'TEST' ); } ); } ); diff --git a/test/specs/repo/extensions/wikibase-edtf.ts b/test/specs/repo/extensions/wikibase-edtf.ts index 9dfa6ed55..e3e7746c4 100644 --- a/test/specs/repo/extensions/wikibase-edtf.ts +++ b/test/specs/repo/extensions/wikibase-edtf.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ItemPage from '../../../helpers/pages/entity/item.page.js'; import SpecialEntityDataPage from '../../../helpers/pages/special/entity-data.page.js'; @@ -12,7 +11,7 @@ describe( 'WikibaseEdtf', function () { it( 'Should allow to create and use the EDTF property', async function () { // create the property const propertyId = await WikibaseApi.createProperty( 'edtf' ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); const rawValue = '1985-04-12T23:20:30'; @@ -37,8 +36,8 @@ describe( 'WikibaseEdtf', function () { const responseSnak = responseData.entities[ itemId ].claims[ propertyId ][ 0 ].mainsnak; - assert.strictEqual( responseSnak.datavalue.value, '1985-04-12T23:20:30' ); - assert.strictEqual( responseSnak.datatype, 'edtf' ); + expect( responseSnak.datavalue.value ).toBe( '1985-04-12T23:20:30' ); + expect( responseSnak.datatype ).toBe( 'edtf' ); // for a pretty screenshot await ItemPage.open( itemId ); diff --git a/test/specs/repo/extensions/wikibase-local-media.ts b/test/specs/repo/extensions/wikibase-local-media.ts index b2dfc7274..bf283b77e 100644 --- a/test/specs/repo/extensions/wikibase-local-media.ts +++ b/test/specs/repo/extensions/wikibase-local-media.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import ItemPage from '../../../helpers/pages/entity/item.page.js'; @@ -32,7 +31,7 @@ describe( 'WikibaseLocalMedia', function () { it( 'Should allow to create a property with localMedia datatype', async function () { propertyId = await WikibaseApi.createProperty( 'localMedia' ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); await PropertyPage.open( propertyId ); @@ -58,11 +57,10 @@ describe( 'WikibaseLocalMedia', function () { const itemId = await WikibaseApi.createItem( 'image-test', data ); await ItemPage.open( itemId ); - const imageSource = await $( '.wikibase-snakview-value img' ).getAttribute( - 'src' + await expect( $( '.wikibase-snakview-value img' ) ).toHaveAttrContaining( + 'src', + 'Image.png' ); - - assert.strictEqual( imageSource.includes( 'Image.png' ), true ); } ); it( 'Should allow to use uploaded image on statement in UI', async function () { diff --git a/test/specs/repo/extensions/wikibase-manifest.ts b/test/specs/repo/extensions/wikibase-manifest.ts index cd8277182..19bda931e 100644 --- a/test/specs/repo/extensions/wikibase-manifest.ts +++ b/test/specs/repo/extensions/wikibase-manifest.ts @@ -1,5 +1,3 @@ -import assert from 'assert'; - describe( 'WikibaseManifest', function () { beforeEach( async function () { await browser.skipIfExtensionNotPresent( this, 'WikibaseManifest' ); @@ -11,20 +9,13 @@ describe( 'WikibaseManifest', function () { ); const data = result.data; - assert.strictEqual( 'wikibase-docker', data.name ); + expect( 'wikibase-docker' ).toBe( data.name ); - assert.strictEqual( - testEnv.vars.WIKIBASE_URL + '/w/api.php', - data.api.action - ); - assert.strictEqual( - testEnv.vars.WIKIBASE_URL + '/w/rest.php', - data.api.rest - ); + expect( testEnv.vars.WIKIBASE_URL + '/w/api.php' ).toBe( data.api.action ); + expect( testEnv.vars.WIKIBASE_URL + '/w/rest.php' ).toBe( data.api.rest ); - assert.strictEqual( - testEnv.vars.WIKIBASE_URL + '/wiki/Special:OAuthConsumerRegistration', - data.oauth.registration_page - ); + expect( + testEnv.vars.WIKIBASE_URL + '/wiki/Special:OAuthConsumerRegistration' + ).toBe( data.oauth.registration_page ); } ); } ); diff --git a/test/specs/repo/property.ts b/test/specs/repo/property.ts index eeb9ff144..ad444440c 100644 --- a/test/specs/repo/property.ts +++ b/test/specs/repo/property.ts @@ -97,8 +97,8 @@ describe( 'Property', function () { it( 'Should be able to revert a change', async function () { await $( '=View history' ).click(); await expect( - ( await $( 'ul.mw-contributions-list' ).$$( 'li' ) ).length - ).toBe( 3 ); + $( 'ul.mw-contributions-list' ).$$( 'li' ) + ).resolves.toHaveLength( 3 ); await $( 'ul.mw-contributions-list' ).$( 'li.before' ).$( 'a=undo' ).click(); await $( 'label=Summary (will be appended to an automatically generated summary):' @@ -108,8 +108,8 @@ describe( 'Property', function () { await $( '=View history' ).click(); await expect( - ( await $( 'ul.mw-contributions-list' ).$$( 'li' ) ).length - ).toBe( 4 ); + $( 'ul.mw-contributions-list' ).$$( 'li' ) + ).resolves.toHaveLength( 4 ); await expect( $( 'span.mw-tag-marker-mw-undo' ) ).toExist(); await expect( $( 'ul.mw-contributions-list' ).$( 'li.before' ) diff --git a/test/specs/repo/queryservice.ts b/test/specs/repo/queryservice.ts index 124c01311..6ef210271 100644 --- a/test/specs/repo/queryservice.ts +++ b/test/specs/repo/queryservice.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { stringify } from 'querystring'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; import { getTestString } from 'wdio-mediawiki/Util.js'; @@ -13,14 +12,14 @@ describe( 'QueryService', function () { { validateStatus: false }, {} ); - assert.strictEqual( result.status, 405 ); + expect( result.status ).toBe( 405 ); } ); it( 'Should be able to get sparql endpoint', async function () { const result = await browser.makeRequest( `${ testEnv.vars.WDQS_PROXY_URL }/bigdata/namespace/wdq/sparql` ); - assert.strictEqual( result.status, 200 ); + expect( result.status ).toBe( 200 ); } ); it( 'Should not be possible to reach blazegraph ldf api that is not enabled', async function () { @@ -28,7 +27,7 @@ describe( 'QueryService', function () { `${ testEnv.vars.WDQS_PROXY_URL }/bigdata/namespace/wdq/ldf`, { validateStatus: false } ); - assert.strictEqual( result.status, 404 ); + expect( result.status ).toBe( 404 ); } ); it( 'Should not be possible to reach blazegraph ldf assets thats not enabled', async function () { @@ -36,7 +35,7 @@ describe( 'QueryService', function () { `${ testEnv.vars.WDQS_PROXY_URL }/bigdata/namespace/wdq/assets`, { validateStatus: false } ); - assert.strictEqual( result.status, 404 ); + expect( result.status ).toBe( 404 ); } ); it( 'Should not be possible to reach blazegraph workbench', async function () { @@ -44,7 +43,7 @@ describe( 'QueryService', function () { `${ testEnv.vars.WDQS_PROXY_URL }/bigdata/#query`, { validateStatus: false } ); - assert.strictEqual( result.status, 404 ); + expect( result.status ).toBe( 404 ); } ); it( 'Should show up with property in queryservice ui after creation', async function () { @@ -78,28 +77,40 @@ describe( 'QueryService', function () { await QueryServiceUIPage.submit(); await QueryServiceUIPage.resultTable; - assert( await QueryServiceUIPage.resultIncludes( 'schema:version' ) ); - assert( await QueryServiceUIPage.resultIncludes( 'schema:dateModified' ) ); - assert( await QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' ) ); + await expect( + QueryServiceUIPage.resultIncludes( 'schema:version' ) + ).resolves.toBe( true ); + await expect( + QueryServiceUIPage.resultIncludes( 'schema:dateModified' ) + ).resolves.toBe( true ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:timestamp' ) + ).resolves.toBe( true ); // label should match on the prefix - assert( await QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel ) ); + await expect( + QueryServiceUIPage.resultIncludes( 'rdfs:label', itemLabel ) + ).resolves.toBe( true ); // should have one statement - assert( await QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' ) ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:statements', '1' ) + ).resolves.toBe( true ); - assert( await QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' ) ); - assert( - await QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '0' ) - ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:sitelinks', '0' ) + ).resolves.toBe( true ); + await expect( + QueryServiceUIPage.resultIncludes( 'wikibase:identifiers', '0' ) + ).resolves.toBe( true ); // property value is set with correct rdf - assert( - await QueryServiceUIPage.resultIncludes( + await expect( + QueryServiceUIPage.resultIncludes( `<${ testEnv.vars.WIKIBASE_URL }/prop/direct/${ propertyId }>`, propertyValue ) - ); + ).resolves.toBe( true ); // query the property using wdt: prefix await QueryServiceUIPage.open( `SELECT * WHERE{ ?s wdt:${ propertyId } ?o }` ); @@ -108,12 +119,12 @@ describe( 'QueryService', function () { await QueryServiceUIPage.resultTable; // should be set only to the item - assert( - await QueryServiceUIPage.resultIncludes( + await expect( + QueryServiceUIPage.resultIncludes( `<${ testEnv.vars.WIKIBASE_URL }/entity/${ itemId }>`, propertyValue ) - ); + ).resolves.toBe( true ); } ); it( 'Should not show up in queryservice ui after deletion', async function () { @@ -143,14 +154,14 @@ describe( 'QueryService', function () { const resultText = await QueryServiceUIPage.resultTable.getText(); // item should not be included - assert( !resultText.includes( 'schema:version' ) ); - assert( !resultText.includes( 'schema:dateModified' ) ); - assert( !resultText.includes( 'wikibase:sitelinks' ) ); - assert( !resultText.includes( 'wikibase:identifiers' ) ); - assert( !resultText.includes( 'rdfs:label' ) ); + expect( resultText.includes( 'schema:version' ) ).toBe( false ); + expect( resultText.includes( 'schema:dateModified' ) ).toBe( false ); + expect( resultText.includes( 'wikibase:sitelinks' ) ).toBe( false ); + expect( resultText.includes( 'wikibase:identifiers' ) ).toBe( false ); + expect( resultText.includes( 'rdfs:label' ) ).toBe( false ); // timestamp always shows - assert( resultText.includes( 'wikibase:timestamp' ) ); + expect( resultText.includes( 'wikibase:timestamp' ) ).toBe( true ); } ); it( 'Should show results for a select query', async function () { diff --git a/test/specs/repo/search.ts b/test/specs/repo/search.ts index 83c2bafdf..781ec831b 100644 --- a/test/specs/repo/search.ts +++ b/test/specs/repo/search.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; describe( 'Search', function () { @@ -15,6 +14,6 @@ describe( 'Search', function () { `${ testEnv.vars.WIKIBASE_URL }/w/api.php?action=wbsearchentities&search=${ itemLabel }&format=json&errorformat=plaintext&language=en&uselang=en&type=item` ); - assert.strictEqual( result.data.search[ 0 ].label, itemLabel ); + expect( result.data.search[ 0 ].label ).toBe( itemLabel ); } ); } ); diff --git a/test/specs/repo/special-item.ts b/test/specs/repo/special-item.ts index 8dde7bc75..d1e4ca57a 100644 --- a/test/specs/repo/special-item.ts +++ b/test/specs/repo/special-item.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import SpecialEntityPage from 'wdio-wikibase/pageobjects/item.page.js'; import SpecialNewItemPage from '../../helpers/pages/special/new-item.page.js'; @@ -18,24 +17,20 @@ describe( 'Special:NewItem', function () { await SpecialEntityPage.addStatementLink; - const labelText = await $( - '.wikibase-entitytermsforlanguageview-label' - ).getText(); - assert.strictEqual( labelText, label ); - - const descriptionText = await $( - '.wikibase-entitytermsforlanguageview-description' - ).getText(); - assert.strictEqual( descriptionText, description ); - - const firstAliasText = await $( - '.wikibase-entitytermsforlanguageview-aliases li:nth-child(1)' - ).getText(); - assert.strictEqual( firstAliasText, firstAlias ); - - const secondAliasText = await $( - '.wikibase-entitytermsforlanguageview-aliases li:nth-child(2)' - ).getText(); - assert.strictEqual( secondAliasText, secondAlias ); + await expect( $( '.wikibase-entitytermsforlanguageview-label' ) ).toHaveText( + label + ); + + await expect( + $( '.wikibase-entitytermsforlanguageview-description' ) + ).toHaveText( description ); + + await expect( + $( '.wikibase-entitytermsforlanguageview-aliases li:nth-child(1)' ) + ).toHaveText( firstAlias ); + + await expect( + $( '.wikibase-entitytermsforlanguageview-aliases li:nth-child(2)' ) + ).toHaveText( secondAlias ); } ); } ); diff --git a/test/specs/repo/special-version.ts b/test/specs/repo/special-version.ts index bb076caf2..4ac33c103 100644 --- a/test/specs/repo/special-version.ts +++ b/test/specs/repo/special-version.ts @@ -1,12 +1,8 @@ -import assert from 'assert'; - describe( 'Special:Version', function () { it( 'Should contain the correct MediaWiki version', async function () { await browser.url( `${ testEnv.vars.WIKIBASE_URL }/wiki/Special:Version` ); - const text = await $( '#sv-software' ).getText(); - assert.strictEqual( - text.includes( `MediaWiki ${ testEnv.vars.MEDIAWIKI_VERSION }` ), - true + await expect( $( '#sv-software' ) ).toHaveTextContaining( + `MediaWiki ${ testEnv.vars.MEDIAWIKI_VERSION }` ); } ); @@ -50,7 +46,7 @@ describe( 'Special:Version', function () { ); await elementSelector.scrollIntoView(); - assert( elementSelector.getText() !== null ); + await expect( elementSelector ).toHaveText( /.+/ ); } ); } ); } ); diff --git a/test/specs/repo_client/extensions/scribunto-item.ts b/test/specs/repo_client/extensions/scribunto-item.ts index 61392523d..b38d938c4 100644 --- a/test/specs/repo_client/extensions/scribunto-item.ts +++ b/test/specs/repo_client/extensions/scribunto-item.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { readFile } from 'fs/promises'; import { stringify } from 'querystring'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; @@ -67,7 +66,7 @@ describe( 'Scribunto Item', function () { ); // should come from executed lua script - assert( executionContent.includes( itemLabel ) ); + expect( executionContent.includes( itemLabel ) ).toBe( true ); } ); // This will generate a change that will dispatch @@ -104,6 +103,6 @@ describe( 'Scribunto Item', function () { expectedDeletionChange ); - assert.deepStrictEqual( actualChange, expectedDeletionChange ); + expect( actualChange ).toEqual( expectedDeletionChange ); } ); } ); diff --git a/test/specs/repo_client/interwiki-links.ts b/test/specs/repo_client/interwiki-links.ts index 1872c3ac1..dfddd0e43 100644 --- a/test/specs/repo_client/interwiki-links.ts +++ b/test/specs/repo_client/interwiki-links.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { readFile } from 'fs/promises'; import { utf8 } from '../../helpers/readFileEncoding.js'; @@ -17,7 +16,9 @@ describe( 'Interwiki links', function () { const clientWikiQueryResults = await browser.dbQuery( 'SELECT iw_url FROM interwiki WHERE iw_prefix = "client_wiki"' ); - assert( clientWikiQueryResults.includes( testEnv.vars.WIKIBASE_CLIENT_URL ) ); + expect( + clientWikiQueryResults.includes( testEnv.vars.WIKIBASE_CLIENT_URL ) + ).toBe( true ); const config = { user: testEnv.vars.DB_USER, @@ -34,6 +35,6 @@ describe( 'Interwiki links', function () { 'SELECT iw_url FROM interwiki WHERE iw_prefix = "my_wiki"', config ); - assert( myWikiQueryResults.includes( testEnv.vars.WIKIBASE_URL ) ); + expect( myWikiQueryResults.includes( testEnv.vars.WIKIBASE_URL ) ).toBe( true ); } ); } ); diff --git a/test/specs/repo_client/item.ts b/test/specs/repo_client/item.ts index cfe1a7dcd..d62eb39ad 100644 --- a/test/specs/repo_client/item.ts +++ b/test/specs/repo_client/item.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { stringify } from 'querystring'; import LoginPage from 'wdio-mediawiki/LoginPage.js'; import { getTestString } from 'wdio-mediawiki/Util.js'; @@ -25,14 +24,16 @@ describe( 'Item', function () { await browser.url( `${ testEnv.vars.WIKIBASE_CLIENT_URL }/wiki/Special:NewItem?uselang=qqx` ); - const notFoundText = await SpecialNewItemPage.firstHeading.getText(); - assert.strictEqual( notFoundText, '(nosuchspecialpage)' ); + await expect( SpecialNewItemPage.firstHeading ).toHaveText( + '(nosuchspecialpage)' + ); } ); it( 'Special:NewItem should be visible on repo', async function () { await SpecialNewItemPage.open( { uselang: 'qqx' } ); - const createNewItem = await SpecialNewItemPage.firstHeading.getText(); - assert.strictEqual( createNewItem, '(special-newitem)' ); + await expect( SpecialNewItemPage.firstHeading ).toHaveText( + '(special-newitem)' + ); } ); it( 'Should create an item on repo', async function () { @@ -67,8 +68,7 @@ describe( 'Item', function () { `{{#statements:${ propertyId }|from=${ itemId }}}` ); // label should come from repo property - assert.equal( bodyText, propertyValue ); - assert( bodyText.includes( propertyValue ) ); + expect( bodyText ).toBe( propertyValue ); } ); // This will generate a change that will dispatch @@ -79,13 +79,13 @@ describe( 'Item', function () { ); await $( '#wb-setsitelink-submit button' ).click(); - const siteLinkValue = await $( - '.wikibase-sitelinklistview-listview li' - ).getText(); - // label should come from repo property - assert( siteLinkValue.includes( 'client_wiki' ) ); - assert( siteLinkValue.includes( pageTitle ) ); + await expect( + $( '.wikibase-sitelinklistview-listview li' ) + ).toHaveTextContaining( 'client_wiki' ); + await expect( + $( '.wikibase-sitelinklistview-listview li' ) + ).toHaveTextContaining( pageTitle ); } ); it( 'Should be able to see site-link change is dispatched to client', async function () { @@ -101,7 +101,7 @@ describe( 'Item', function () { expectedSiteLinkChange ); - assert.deepStrictEqual( actualChange, expectedSiteLinkChange ); + expect( actualChange ).toEqual( expectedSiteLinkChange ); } ); // This will generate a change that will dispatch @@ -138,6 +138,6 @@ describe( 'Item', function () { expectedTestDeletionChange ); - assert.deepStrictEqual( actualChange, expectedTestDeletionChange ); + expect( actualChange ).toEqual( expectedTestDeletionChange ); } ); } ); diff --git a/test/specs/upgrade/pre-upgrade.ts b/test/specs/upgrade/pre-upgrade.ts index 323e99c3e..e93baef5a 100644 --- a/test/specs/upgrade/pre-upgrade.ts +++ b/test/specs/upgrade/pre-upgrade.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { getTestString } from 'wdio-mediawiki/Util.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; @@ -28,8 +27,8 @@ describe( 'Wikibase pre upgrade', function () { data ); - assert.strictEqual( itemId.startsWith( 'Q' ), true ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( itemId.startsWith( 'Q' ) ).toBe( true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); } } ); @@ -53,7 +52,7 @@ describe( 'Wikibase pre upgrade', function () { const itemId = await WikibaseApi.createItem( itemLabel, data ); - assert.strictEqual( itemId.startsWith( 'Q' ), true ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( itemId.startsWith( 'Q' ) ).toBe( true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); } ); } ); diff --git a/test/specs/upgrade/queryservice-post-upgrade.ts b/test/specs/upgrade/queryservice-post-upgrade.ts index 4ac385b68..1de526e37 100644 --- a/test/specs/upgrade/queryservice-post-upgrade.ts +++ b/test/specs/upgrade/queryservice-post-upgrade.ts @@ -4,7 +4,6 @@ for unknown reasons. This spec existed but was skipped in the code the Wikibase team inherited. */ -import assert from 'assert'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; import { getElementByURI } from '../../helpers/blazegraph.js'; import Binding from '../../types/binding.js'; @@ -39,8 +38,8 @@ describe( 'Wikibase post upgrade', function () { newItemId = await WikibaseApi.createItem( itemLabel, data ); - assert.strictEqual( newItemId.startsWith( 'Q' ), true ); - assert.strictEqual( newPropertyId.startsWith( 'P' ), true ); + expect( newItemId.startsWith( 'Q' ) ).toBe( true ); + expect( newPropertyId.startsWith( 'P' ) ).toBe( true ); } ); it( 'New item should show up in Queryservice', async function () { @@ -57,7 +56,7 @@ describe( 'Wikibase post upgrade', function () { } ); - assert.strictEqual( bindings.length, 9 ); + expect( bindings ).toHaveLength( 9 ); const statement = getElementByURI( testEnv.vars.WIKIBASE_URL + '/prop/' + newPropertyId, @@ -93,14 +92,14 @@ describe( 'Wikibase post upgrade', function () { bindings ); - assert( dateModified !== null ); - assert( schemaVersion !== null ); - assert( siteLinks !== null ); - assert( identifiers !== null ); - assert( timestamp !== null ); - assert( statement !== null ); + expect( dateModified ).toEqual( expect.anything() ); + expect( schemaVersion ).toEqual( expect.anything() ); + expect( siteLinks ).toEqual( expect.anything() ); + expect( identifiers ).toEqual( expect.anything() ); + expect( timestamp ).toEqual( expect.anything() ); + expect( statement ).toEqual( expect.anything() ); - assert.strictEqual( property.o.value, propertyValue ); - assert.strictEqual( itemLabelValue.o.value, itemLabel ); + expect( property.o.value ).toBe( propertyValue ); + expect( itemLabelValue.o.value ).toBe( itemLabel ); } ); } ); diff --git a/test/specs/upgrade/queryservice-pre-and-post-upgrade.ts b/test/specs/upgrade/queryservice-pre-and-post-upgrade.ts index 0e9bed453..e60246f13 100644 --- a/test/specs/upgrade/queryservice-pre-and-post-upgrade.ts +++ b/test/specs/upgrade/queryservice-pre-and-post-upgrade.ts @@ -4,7 +4,6 @@ for unknown reasons. This spec existed but was skipped in the code the Wikibase team inherited. */ -import assert from 'assert'; import { getElementByURI } from '../../helpers/blazegraph.js'; import ItemPage from '../../helpers/pages/entity/item.page.js'; import SpecialEntityDataPage from '../../helpers/pages/special/entity-data.page.js'; @@ -27,10 +26,10 @@ describe( 'Wikibase post upgrade', function () { const success = result.data.success; const searchResults = result.data.search; - assert.strictEqual( success, 1 ); - assert.strictEqual( searchResults.length, 1 ); - assert.strictEqual( searchResults[ 0 ].match.text, 'UpgradeItem' ); - assert.strictEqual( searchResults[ 0 ].match.type, 'label' ); + expect( success ).toBe( 1 ); + expect( searchResults ).toHaveLength( 1 ); + expect( searchResults[ 0 ].match.text ).toBe( 'UpgradeItem' ); + expect( searchResults[ 0 ].match.type ).toBe( 'label' ); oldItemID = searchResults[ 0 ].id; @@ -41,7 +40,7 @@ describe( 'Wikibase post upgrade', function () { const data = await SpecialEntityDataPage.getData( oldItemID ); const properties = Object.keys( data.entities[ oldItemID ].claims ); - assert.strictEqual( properties.length, 1 ); + expect( properties ).toHaveLength( 1 ); oldPropertyID = properties[ 0 ]; } ); @@ -61,7 +60,7 @@ describe( 'Wikibase post upgrade', function () { } ); - assert.strictEqual( bindings.length, 9 ); + expect( bindings ).toHaveLength( 9 ); const statement = getElementByURI( `${ testEnv.vars.WIKIBASE_URL }/prop/${ oldPropertyID }`, @@ -98,17 +97,17 @@ describe( 'Wikibase post upgrade', function () { bindings ); - assert( dateModified !== null ); - assert( schemaVersion !== null ); - assert( siteLinks !== null ); - assert( identifiers !== null ); - assert( timestamp !== null ); - assert( statement !== null ); + expect( dateModified ).toEqual( expect.anything() ); + expect( schemaVersion ).toEqual( expect.anything() ); + expect( siteLinks ).toEqual( expect.anything() ); + expect( identifiers ).toEqual( expect.anything() ); + expect( timestamp ).toEqual( expect.anything() ); + expect( statement ).toEqual( expect.anything() ); - assert( property !== null ); - assert.strictEqual( property.o.value, 'UpgradeItemStringValue' ); + expect( property ).toEqual( expect.anything() ); + expect( property.o.value ).toBe( 'UpgradeItemStringValue' ); - assert( itemLabelValue !== null ); - assert.strictEqual( itemLabelValue.o.value, 'UpgradeItem' ); + expect( itemLabelValue ).toEqual( expect.anything() ); + expect( itemLabelValue.o.value ).toBe( 'UpgradeItem' ); } ); } ); diff --git a/test/specs/upgrade/upgrade.ts b/test/specs/upgrade/upgrade.ts index 893343e02..afef2fc07 100644 --- a/test/specs/upgrade/upgrade.ts +++ b/test/specs/upgrade/upgrade.ts @@ -1,4 +1,3 @@ -import assert from 'assert'; import { spawnSync } from 'child_process'; import { getTestString } from 'wdio-mediawiki/Util.js'; import WikibaseApi from 'wdio-wikibase/wikibase.api.js'; @@ -65,8 +64,8 @@ describe( 'Wikibase upgrade', function () { getTestString( itemLabel ), data ); - assert.strictEqual( itemId.startsWith( 'Q' ), true ); - assert.strictEqual( propertyId.startsWith( 'P' ), true ); + expect( itemId.startsWith( 'Q' ) ).toBe( true ); + expect( propertyId.startsWith( 'P' ) ).toBe( true ); } } ); @@ -77,10 +76,10 @@ describe( 'Wikibase upgrade', function () { const success = result.data.success; const searchResults = result.data.search; - assert.strictEqual( success, 1 ); - assert.strictEqual( searchResults.length, 1 ); - assert.strictEqual( searchResults[ 0 ].match.text, 'UpgradeItem' ); - assert.strictEqual( searchResults[ 0 ].match.type, 'label' ); + expect( success ).toBe( 1 ); + expect( searchResults ).toHaveLength( 1 ); + expect( searchResults[ 0 ].match.text ).toBe( 'UpgradeItem' ); + expect( searchResults[ 0 ].match.type ).toBe( 'label' ); oldItemID = searchResults[ 0 ].id; @@ -89,6 +88,11 @@ describe( 'Wikibase upgrade', function () { it( 'should show up in Special:EntityData with json', async function () { const data = await SpecialEntityDataPage.getData( oldItemID ); - assert( data.entities[ oldItemID ].claims[ 0 ] !== null ); + expect( data.entities[ oldItemID ].claims ).toEqual( expect.anything() ); + expect( Object.keys( data.entities[ oldItemID ].claims ) ).toHaveLength( 1 ); + const oldPropertyId = Object.keys( data.entities[ oldItemID ].claims )[ 0 ]; + expect( data.entities[ oldItemID ].claims[ oldPropertyId ] ).toEqual( + expect.anything() + ); } ); } );